diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/gtest/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/gtest/arena.cpp | 39 |
2 files changed, 40 insertions, 0 deletions
diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index 9b648fb65..c3d281f1c 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -2,6 +2,7 @@ include_directories(../../third_party/googletest/googletest/include) include_directories(../../src/wasm) set(unittest_SOURCES + arena.cpp binary-reader.cpp cfg.cpp dfa_minimization.cpp diff --git a/test/gtest/arena.cpp b/test/gtest/arena.cpp new file mode 100644 index 000000000..7453ea9f6 --- /dev/null +++ b/test/gtest/arena.cpp @@ -0,0 +1,39 @@ +#include "mixed_arena.h" +#include "gtest/gtest.h" + +using ArenaTest = ::testing::Test; + +TEST_F(ArenaTest, Swap) { + MixedArena arena; + + ArenaVector<int> a(arena); + a.push_back(10); + a.push_back(20); + + ArenaVector<int> b(arena); + + EXPECT_EQ(a.size(), 2U); + EXPECT_EQ(b.size(), 0U); + + a.swap(b); + + EXPECT_EQ(a.size(), 0U); + EXPECT_EQ(b.size(), 2U); + + a.swap(b); + + EXPECT_EQ(a.size(), 2U); + EXPECT_EQ(b.size(), 0U); + + // Now reverse a and b. The swap should be the same. + + b.swap(a); + + EXPECT_EQ(a.size(), 0U); + EXPECT_EQ(b.size(), 2U); + + b.swap(a); + + EXPECT_EQ(a.size(), 2U); + EXPECT_EQ(b.size(), 0U); +} |