Skip to content

Commit cbce4bc

Browse files
committed
Unit test of irept's public API
1 parent abdb044 commit cbce4bc

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

Diff for: unit/util/irep.cpp

+52-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,57 @@ SCENARIO("irept_memory", "[core][utils][irept]")
1414
REQUIRE(sizeof(irept) == sizeof(void *));
1515
}
1616

17+
THEN("The storage size of an irept is fixed")
18+
{
19+
#ifdef SHARING
20+
const std::size_t ref_count_size = sizeof(unsigned);
21+
#else
22+
const std::size_t ref_count_size = 0;
23+
#endif
24+
25+
#ifndef USE_STRING
26+
const std::size_t data_size = sizeof(dstringt);
27+
REQUIRE(sizeof(dstringt) == sizeof(unsigned));
28+
#else
29+
const std::size_t data_size = sizeof(std::string);
30+
REQUIRE(sizeof(std::string) == sizeof(void *));
31+
#endif
32+
33+
const std::size_t sub_size = sizeof(std::vector<int>);
34+
#ifndef _GLIBCXX_DEBUG
35+
REQUIRE(sizeof(std::vector<int>) == 3 * sizeof(void *));
36+
#endif
37+
38+
#ifndef SUB_IS_LIST
39+
const std::size_t named_size = sizeof(std::map<int, int>);
40+
# ifndef _GLIBCXX_DEBUG
41+
# ifdef __APPLE__
42+
REQUIRE(sizeof(std::map<int, int>) == 3 * sizeof(void *));
43+
# elif defined(_WIN32)
44+
REQUIRE(sizeof(std::map<int, int>) == 2 * sizeof(void *));
45+
# else
46+
REQUIRE(sizeof(std::map<int, int>) == 6 * sizeof(void *));
47+
# endif
48+
# endif
49+
#else
50+
const std::size_t named_size = sizeof(std::list<int>);
51+
# ifndef _GLIBCXX_DEBUG
52+
REQUIRE(sizeof(std::list<int>) == 3 * sizeof(void *));
53+
# endif
54+
#endif
55+
56+
#ifdef HASH_CODE
57+
const std::size_t hash_code_size = sizeof(std::size_t);
58+
#else
59+
const std::size_t hash_code_size = 0;
60+
#endif
61+
62+
REQUIRE(
63+
sizeof(irept::dt) ==
64+
ref_count_size + data_size + sub_size + 2 * named_size +
65+
hash_code_size);
66+
}
67+
1768
THEN("get_nil_irep yields ID_nil")
1869
{
1970
REQUIRE(get_nil_irep().id() == ID_nil);
@@ -88,7 +139,7 @@ SCENARIO("irept_memory", "[core][utils][irept]")
88139
REQUIRE(irep.find("a_new_element").id() == "some_id");
89140

90141
irept irep2("second_irep");
91-
irep.add("a_new_element", irep2);
142+
irept &e2 = irep.add("a_new_element", irep2);
92143
REQUIRE(irep.find("a_new_element").id() == "second_irep");
93144
REQUIRE(irep.get_named_sub().size() == 1);
94145

0 commit comments

Comments
 (0)