| 17 | namespace { |
| 18 | |
| 19 | void |
| 20 | testString() |
| 21 | { |
| 22 | StringTable st; |
| 23 | |
| 24 | size_t size = st.size(); |
| 25 | assert(size == 0); |
| 26 | assert(!st.hasString("foo")); |
| 27 | |
| 28 | StringTableIndex index = st.intern("foo"); |
| 29 | assert(index == st.lookup("foo")); |
| 30 | assert(st.lookup(index) == "foo"); |
| 31 | assert(st.hasString("foo")); |
| 32 | |
| 33 | size = st.size(); |
| 34 | assert(size == 1); |
| 35 | |
| 36 | bool thrown = false; |
| 37 | try { |
| 38 | index = st.lookup("bar"); |
| 39 | } catch (std::exception &e) { |
| 40 | thrown = true; |
| 41 | } |
| 42 | assert (thrown); |
| 43 | |
| 44 | thrown = false; |
| 45 | try { |
| 46 | std::string s = st.lookup(StringTableIndex(1)); |
| 47 | } catch (std::exception &e) { |
| 48 | thrown = true; |
| 49 | } |
| 50 | assert (thrown); |
| 51 | |
| 52 | assert(!st.hasString("bar")); |
| 53 | |
| 54 | index = st.intern("bar"); |
| 55 | assert(index == st.lookup("bar")); |
| 56 | assert(st.lookup(index) == "bar"); |
| 57 | assert(0 == st.lookup("foo").index()); |
| 58 | assert(st.lookup(StringTableIndex(0)) == "foo"); |
| 59 | assert(st.hasString("bar")); |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | testWString() |
no test coverage detected