Initial commit
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
add_executable(test_intrusive_list intrusive_list_tests.cc)
|
||||
target_include_directories(test_intrusive_list
|
||||
PUBLIC "${PROJECT_SOURCE_DIR}/include")
|
||||
target_link_libraries(test_intrusive_list
|
||||
gtest)
|
||||
add_test(NAME test_intrusive_list COMMAND test_intrusive_list)
|
||||
set_target_properties(test_intrusive_list PROPERTIES FOLDER "ozz/tests/base")
|
||||
|
||||
add_executable(test_std_containers std_containers_tests.cc)
|
||||
target_link_libraries(test_std_containers
|
||||
ozz_base
|
||||
gtest)
|
||||
add_test(NAME test_std_containers COMMAND test_std_containers)
|
||||
set_target_properties(test_std_containers PROPERTIES FOLDER "ozz/tests/base")
|
||||
|
||||
add_executable(test_std_containers_archive
|
||||
std_containers_archive_tests.cc)
|
||||
target_link_libraries(test_std_containers_archive
|
||||
ozz_base
|
||||
gtest)
|
||||
add_test(NAME test_std_containers_archive COMMAND test_std_containers_archive)
|
||||
set_target_properties(test_std_containers_archive PROPERTIES FOLDER "ozz/tests/base")
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,145 @@
|
||||
//----------------------------------------------------------------------------//
|
||||
// //
|
||||
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
|
||||
// and distributed under the MIT License (MIT). //
|
||||
// //
|
||||
// Copyright (c) Guillaume Blanc //
|
||||
// //
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a //
|
||||
// copy of this software and associated documentation files (the "Software"), //
|
||||
// to deal in the Software without restriction, including without limitation //
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
|
||||
// and/or sell copies of the Software, and to permit persons to whom the //
|
||||
// Software is furnished to do so, subject to the following conditions: //
|
||||
// //
|
||||
// The above copyright notice and this permission notice shall be included in //
|
||||
// all copies or substantial portions of the Software. //
|
||||
// //
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
|
||||
// DEALINGS IN THE SOFTWARE. //
|
||||
// //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include "ozz/base/containers/string_archive.h"
|
||||
#include "ozz/base/containers/vector_archive.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "ozz/base/io/archive.h"
|
||||
|
||||
TEST(string, Archive) {
|
||||
for (int e = 0; e < 2; ++e) {
|
||||
ozz::Endianness endianess = e == 0 ? ozz::kBigEndian : ozz::kLittleEndian;
|
||||
|
||||
ozz::io::MemoryStream stream;
|
||||
ASSERT_TRUE(stream.opened());
|
||||
|
||||
// Writes.
|
||||
ozz::io::OArchive o(&stream, endianess);
|
||||
ozz::string empty_o;
|
||||
o << empty_o;
|
||||
|
||||
ozz::string small_o("Forty-six");
|
||||
o << small_o;
|
||||
|
||||
ozz::string big_o(
|
||||
"Forty-six is a Wedderburn-Etherington number, an "
|
||||
"enneagonal number and a centered triangular number. It is the sum of "
|
||||
"the totient function for the first twelve integers. 46 is the largest "
|
||||
"even integer that can't be expressed as a sum of two abundant numbers."
|
||||
"46 is the 16th semiprime. 46 is the third semiprime with a semiprime"
|
||||
"aliquot sum. The aliquot sequence of 46 is (46,26,16,15,9,4,3,1,0)."
|
||||
"Since it is possible to find sequences of 46 consecutive integers "
|
||||
"such that each inner member shares a factor with either the first or "
|
||||
"the last member, 46 is an Erdos-Woods number.");
|
||||
o << big_o;
|
||||
|
||||
// Rewrite for the string reuse test.
|
||||
ozz::string reuse_o("Forty-six");
|
||||
o << reuse_o;
|
||||
|
||||
// Reads.
|
||||
stream.Seek(0, ozz::io::Stream::kSet);
|
||||
ozz::io::IArchive i(&stream);
|
||||
|
||||
ozz::string empty_i;
|
||||
i >> empty_i;
|
||||
EXPECT_STREQ(empty_o.c_str(), empty_i.c_str());
|
||||
|
||||
ozz::string small_i;
|
||||
i >> small_i;
|
||||
EXPECT_STREQ(small_o.c_str(), small_i.c_str());
|
||||
|
||||
ozz::string big_i;
|
||||
i >> big_i;
|
||||
EXPECT_STREQ(big_o.c_str(), big_i.c_str());
|
||||
|
||||
ozz::string reuse_i("already used string");
|
||||
i >> reuse_i;
|
||||
EXPECT_STREQ(reuse_o.c_str(), reuse_i.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Vector, Archive) {
|
||||
for (int e = 0; e < 2; ++e) {
|
||||
ozz::Endianness endianess = e == 0 ? ozz::kBigEndian : ozz::kLittleEndian;
|
||||
|
||||
ozz::io::MemoryStream stream;
|
||||
ASSERT_TRUE(stream.opened());
|
||||
|
||||
// Writes.
|
||||
ozz::io::OArchive o(&stream, endianess);
|
||||
ozz::vector<int> empty_o;
|
||||
o << empty_o;
|
||||
|
||||
ozz::vector<int> small_o(5);
|
||||
std::generate(small_o.begin(), small_o.end(), std::rand);
|
||||
o << small_o;
|
||||
|
||||
ozz::vector<int> big_o(1263);
|
||||
std::generate(big_o.begin(), big_o.end(), std::rand);
|
||||
o << big_o;
|
||||
|
||||
// Rewrite for the Vector reuse test.
|
||||
ozz::vector<int> reuse_o(46);
|
||||
std::generate(reuse_o.begin(), reuse_o.end(), std::rand);
|
||||
o << reuse_o;
|
||||
|
||||
// Reads.
|
||||
stream.Seek(0, ozz::io::Stream::kSet);
|
||||
ozz::io::IArchive i(&stream);
|
||||
|
||||
ozz::vector<int> empty_i;
|
||||
i >> empty_i;
|
||||
EXPECT_EQ(empty_i.size(), 0u);
|
||||
|
||||
ozz::vector<int> small_i;
|
||||
i >> small_i;
|
||||
EXPECT_EQ(small_o.size(), small_i.size());
|
||||
for (size_t j = 0; j < empty_i.size(); ++j) {
|
||||
EXPECT_EQ(small_o[j], small_i[j]);
|
||||
}
|
||||
|
||||
ozz::vector<int> big_i;
|
||||
i >> big_i;
|
||||
EXPECT_EQ(big_o.size(), big_i.size());
|
||||
for (size_t j = 0; j < big_i.size(); ++j) {
|
||||
EXPECT_EQ(big_o[j], big_i[j]);
|
||||
}
|
||||
|
||||
ozz::vector<int> reuse_i(3);
|
||||
std::generate(reuse_i.begin(), reuse_i.end(), std::rand);
|
||||
i >> reuse_i;
|
||||
EXPECT_EQ(reuse_o.size(), reuse_i.size());
|
||||
for (size_t j = 0; j < reuse_i.size(); ++j) {
|
||||
EXPECT_EQ(reuse_o[j], reuse_i[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
//----------------------------------------------------------------------------//
|
||||
// //
|
||||
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
|
||||
// and distributed under the MIT License (MIT). //
|
||||
// //
|
||||
// Copyright (c) Guillaume Blanc //
|
||||
// //
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a //
|
||||
// copy of this software and associated documentation files (the "Software"), //
|
||||
// to deal in the Software without restriction, including without limitation //
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
|
||||
// and/or sell copies of the Software, and to permit persons to whom the //
|
||||
// Software is furnished to do so, subject to the following conditions: //
|
||||
// //
|
||||
// The above copyright notice and this permission notice shall be included in //
|
||||
// all copies or substantial portions of the Software. //
|
||||
// //
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
|
||||
// DEALINGS IN THE SOFTWARE. //
|
||||
// //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ozz/base/containers/deque.h"
|
||||
#include "ozz/base/containers/list.h"
|
||||
#include "ozz/base/containers/map.h"
|
||||
#include "ozz/base/containers/queue.h"
|
||||
#include "ozz/base/containers/set.h"
|
||||
#include "ozz/base/containers/stack.h"
|
||||
#include "ozz/base/containers/string.h"
|
||||
#include "ozz/base/containers/unordered_map.h"
|
||||
#include "ozz/base/containers/unordered_set.h"
|
||||
#include "ozz/base/containers/vector.h"
|
||||
#include "ozz/base/gtest_helper.h"
|
||||
#include "ozz/base/span.h"
|
||||
|
||||
TEST(Vector, Containers) {
|
||||
typedef ozz::vector<int> Container;
|
||||
Container container;
|
||||
container.push_back(1);
|
||||
container.insert(container.begin(), 0);
|
||||
container.push_back(2);
|
||||
container.push_back(std::move(3));
|
||||
EXPECT_EQ(container[0], 0);
|
||||
EXPECT_EQ(container[1], 1);
|
||||
EXPECT_EQ(container[2], 2);
|
||||
EXPECT_EQ(container[3], 3);
|
||||
|
||||
Container container2 = std::move(container);
|
||||
}
|
||||
|
||||
TEST(VectorExtensions, Containers) {
|
||||
typedef ozz::vector<int> Container;
|
||||
Container container;
|
||||
int* null = nullptr;
|
||||
|
||||
// Non-mutable access.
|
||||
EXPECT_EQ(array_begin(container), null);
|
||||
EXPECT_EQ(array_end(container), null);
|
||||
EXPECT_EQ(array_end(container), array_begin(container));
|
||||
EXPECT_TRUE(make_span(container).empty());
|
||||
|
||||
container.push_back(1);
|
||||
container.push_back(2);
|
||||
EXPECT_EQ(*array_begin(container), 1);
|
||||
EXPECT_EQ(*(array_begin(container) + 1), 2);
|
||||
EXPECT_EQ(array_begin(container) + 2, array_end(container));
|
||||
EXPECT_NE(array_end(container), null);
|
||||
EXPECT_EQ(*(array_end(container) - 2), 1);
|
||||
EXPECT_EQ(array_end(container) - array_begin(container), 2);
|
||||
EXPECT_EQ(make_span(container).begin(), array_begin(container));
|
||||
EXPECT_EQ(make_span(container).end(), array_end(container));
|
||||
|
||||
const Container const_container(container);
|
||||
EXPECT_EQ(*array_begin(const_container), 1);
|
||||
EXPECT_EQ(*(array_begin(const_container) + 1), 2);
|
||||
EXPECT_EQ(array_begin(const_container) + 2, array_end(const_container));
|
||||
EXPECT_NE(array_end(const_container), null);
|
||||
EXPECT_EQ(*(array_end(const_container) - 2), 1);
|
||||
EXPECT_EQ(array_end(const_container) - array_begin(const_container), 2);
|
||||
EXPECT_EQ(make_span(const_container).begin(), array_begin(const_container));
|
||||
EXPECT_EQ(make_span(const_container).end(), array_end(const_container));
|
||||
|
||||
// Mutable access.
|
||||
*array_begin(container) = 0;
|
||||
EXPECT_EQ(*array_begin(container), 0);
|
||||
EXPECT_EQ(*(array_begin(container) + 1), 2);
|
||||
}
|
||||
|
||||
TEST(Deque, Containers) {
|
||||
typedef ozz::deque<int> Container;
|
||||
Container container;
|
||||
container.push_back(1);
|
||||
container.push_front(0);
|
||||
container.push_back(2);
|
||||
EXPECT_EQ(container[0], 0);
|
||||
EXPECT_EQ(container[1], 1);
|
||||
EXPECT_EQ(container[2], 2);
|
||||
container.clear();
|
||||
|
||||
Container container2 = std::move(container);
|
||||
}
|
||||
|
||||
TEST(List, Containers) {
|
||||
typedef ozz::list<int> Container;
|
||||
Container container;
|
||||
container.push_back(1);
|
||||
container.push_front(0);
|
||||
container.push_back(2);
|
||||
EXPECT_EQ(container.front(), 0);
|
||||
EXPECT_EQ(container.back(), 2);
|
||||
container.clear();
|
||||
|
||||
Container container2 = std::move(container);
|
||||
}
|
||||
|
||||
TEST(Stack, Containers) {
|
||||
typedef ozz::stack<int> Container;
|
||||
Container container;
|
||||
container.push(1);
|
||||
container.push(2);
|
||||
EXPECT_EQ(container.top(), 2);
|
||||
container.pop();
|
||||
EXPECT_EQ(container.top(), 1);
|
||||
container.pop();
|
||||
|
||||
Container container2 = std::move(container);
|
||||
}
|
||||
|
||||
TEST(Queue, Containers) {
|
||||
{
|
||||
typedef ozz::queue<int> Container;
|
||||
Container container;
|
||||
container.push(1);
|
||||
container.push(2);
|
||||
EXPECT_EQ(container.back(), 2);
|
||||
EXPECT_EQ(container.front(), 1);
|
||||
container.pop();
|
||||
EXPECT_EQ(container.back(), 2);
|
||||
container.pop();
|
||||
|
||||
Container container2 = std::move(container);
|
||||
}
|
||||
{
|
||||
typedef ozz::priority_queue<int> Container;
|
||||
Container container;
|
||||
container.push(1);
|
||||
container.push(2);
|
||||
container.push(0);
|
||||
EXPECT_EQ(container.top(), 2);
|
||||
container.pop();
|
||||
EXPECT_EQ(container.top(), 1);
|
||||
container.pop();
|
||||
EXPECT_EQ(container.top(), 0);
|
||||
container.pop();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Set, Containers) {
|
||||
{
|
||||
typedef ozz::set<int> Container;
|
||||
Container container;
|
||||
EXPECT_TRUE(container.insert('c').second);
|
||||
EXPECT_TRUE(container.insert('a').second);
|
||||
EXPECT_TRUE(container.insert('b').second);
|
||||
EXPECT_FALSE(container.insert('b').second);
|
||||
EXPECT_TRUE(container.find('a') == container.begin());
|
||||
EXPECT_TRUE(container.find('c') == --container.end());
|
||||
EXPECT_EQ(container.erase('c'), 1u);
|
||||
|
||||
EXPECT_TRUE(container.find('b') == --container.end());
|
||||
container.clear();
|
||||
|
||||
Container container2 = std::move(container);
|
||||
}
|
||||
{
|
||||
typedef ozz::multiset<int> Container;
|
||||
Container container;
|
||||
container.insert('c');
|
||||
container.insert('a');
|
||||
container.insert('b');
|
||||
container.insert('a');
|
||||
EXPECT_TRUE(container.find('a') == container.begin() ||
|
||||
container.find('a') == ++container.begin());
|
||||
EXPECT_TRUE(container.find('c') == --container.end());
|
||||
EXPECT_EQ(container.erase('c'), 1u);
|
||||
EXPECT_TRUE(container.find('c') == container.end());
|
||||
EXPECT_EQ(container.erase('a'), 2u);
|
||||
EXPECT_TRUE(container.find('a') == container.end());
|
||||
container.clear();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UnorderedSet, Containers) {
|
||||
{
|
||||
typedef ozz::unordered_set<int> Container;
|
||||
Container container;
|
||||
EXPECT_TRUE(container.insert('c').second);
|
||||
EXPECT_TRUE(container.insert('a').second);
|
||||
EXPECT_TRUE(container.insert('b').second);
|
||||
EXPECT_FALSE(container.insert('a').second);
|
||||
EXPECT_TRUE(container.find('a') != container.end());
|
||||
EXPECT_TRUE(container.find('c') != container.end());
|
||||
EXPECT_EQ(container.erase('c'), 1u);
|
||||
EXPECT_TRUE(container.find('c') == container.end());
|
||||
container.clear();
|
||||
}
|
||||
{
|
||||
typedef ozz::unordered_multiset<int> Container;
|
||||
Container container;
|
||||
container.insert('c');
|
||||
container.insert('a');
|
||||
container.insert('b');
|
||||
container.insert('a');
|
||||
EXPECT_TRUE(container.find('a') != container.end());
|
||||
EXPECT_TRUE(container.find('c') != container.end());
|
||||
EXPECT_EQ(container.erase('c'), 1u);
|
||||
EXPECT_TRUE(container.find('c') == container.end());
|
||||
EXPECT_EQ(container.erase('a'), 2u);
|
||||
EXPECT_TRUE(container.find('a') == container.end());
|
||||
container.clear();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Map, Containers) {
|
||||
{
|
||||
typedef ozz::map<char, int> Container;
|
||||
Container container;
|
||||
container['a'] = -3;
|
||||
container['c'] = -1;
|
||||
container['b'] = -2;
|
||||
container['d'] = 1;
|
||||
EXPECT_EQ(container['a'], -3);
|
||||
EXPECT_EQ(container['b'], -2);
|
||||
EXPECT_EQ(container['c'], -1);
|
||||
EXPECT_EQ(container['d'], 1);
|
||||
EXPECT_EQ(container.erase('d'), 1u);
|
||||
EXPECT_TRUE(container.find('d') == container.end());
|
||||
container.clear();
|
||||
|
||||
Container container2 = std::move(container);
|
||||
}
|
||||
{
|
||||
typedef ozz::multimap<char, int> Container;
|
||||
Container container;
|
||||
container.insert(std::pair<char, int>('a', -3));
|
||||
container.insert(std::pair<char, int>('c', -1));
|
||||
container.insert(std::pair<char, int>('b', -2));
|
||||
container.insert(std::pair<char, int>('d', 1));
|
||||
container.insert(std::pair<char, int>('d', 2));
|
||||
EXPECT_EQ(container.find('a')->second, -3);
|
||||
EXPECT_EQ(container.find('b')->second, -2);
|
||||
EXPECT_EQ(container.find('c')->second, -1);
|
||||
EXPECT_TRUE(container.find('d')->second == 1 ||
|
||||
container.find('d')->second == 2);
|
||||
EXPECT_EQ(container.erase('d'), 2u);
|
||||
EXPECT_TRUE(container.find('d') == container.end());
|
||||
container.clear();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UnorderedMap, Containers) {
|
||||
{
|
||||
typedef ozz::unordered_map<char, int> Container;
|
||||
Container container;
|
||||
container['a'] = -3;
|
||||
container['c'] = -1;
|
||||
container['b'] = -2;
|
||||
container['d'] = 1;
|
||||
EXPECT_EQ(container['a'], -3);
|
||||
EXPECT_EQ(container['b'], -2);
|
||||
EXPECT_EQ(container['c'], -1);
|
||||
EXPECT_EQ(container['d'], 1);
|
||||
EXPECT_EQ(container.erase('d'), 1u);
|
||||
EXPECT_TRUE(container.find('d') == container.end());
|
||||
container.clear();
|
||||
}
|
||||
{
|
||||
typedef ozz::unordered_multimap<char, int> Container;
|
||||
Container container;
|
||||
container.insert(std::pair<char, int>('a', -3));
|
||||
container.insert(std::pair<char, int>('c', -1));
|
||||
container.insert(std::pair<char, int>('b', -2));
|
||||
container.insert(std::pair<char, int>('d', 1));
|
||||
container.insert(std::pair<char, int>('d', 2));
|
||||
EXPECT_EQ(container.find('a')->second, -3);
|
||||
EXPECT_EQ(container.find('b')->second, -2);
|
||||
EXPECT_EQ(container.find('c')->second, -1);
|
||||
EXPECT_TRUE(container.find('d')->second == 1 ||
|
||||
container.find('d')->second == 2);
|
||||
EXPECT_EQ(container.erase('d'), 2u);
|
||||
EXPECT_TRUE(container.find('d') == container.end());
|
||||
container.clear();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(string, Containers) {
|
||||
typedef ozz::string string;
|
||||
string str;
|
||||
EXPECT_EQ(str.size(), 0u);
|
||||
str += "a string";
|
||||
EXPECT_STREQ(str.c_str(), "a string");
|
||||
|
||||
string str2 = std::move(str);
|
||||
EXPECT_STREQ(str2.c_str(), "a string");
|
||||
|
||||
str2.clear();
|
||||
EXPECT_EQ(str2.size(), 0u);
|
||||
}
|
||||
Reference in New Issue
Block a user