| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "gate/tests.hpp" | ||
| 2 | #include "gate/hashes.hpp" | ||
| 3 | #include "gate/guids.hpp" | ||
| 4 | #include "gate/times.hpp" | ||
| 5 | #include "gate/properties.hpp" | ||
| 6 | #include "gate/objects.hpp" | ||
| 7 | |||
| 8 | |||
| 9 | using namespace gate; | ||
| 10 | |||
| 11 | |||
| 12 | template<class T> | ||
| 13 | 60 | void checkTypeHash(T const& instance) | |
| 14 | { | ||
| 15 |
1/2✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
|
120 | TypeHash<T> generator; |
| 16 | 60 | hash_code_t code = 0; | |
| 17 |
3/12✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 30 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 30 times.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
60 | GATEXX_TEST_CHECK_NOTHROW(code = generator(instance)); |
| 18 |
4/12✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 30 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 30 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 30 times.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
|
60 | GATEXX_TEST_CHECK(code != 0); |
| 19 | 60 | } | |
| 20 | |||
| 21 | template<class T> | ||
| 22 | 22 | void checkNumTypeHash() | |
| 23 | { | ||
| 24 | 22 | T instance = static_cast<T>(123); | |
| 25 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
22 | checkTypeHash<T>(instance); |
| 26 | 22 | } | |
| 27 | |||
| 28 | 1 | static void checkCStrTypeHash() | |
| 29 | { | ||
| 30 | static gate_cstr_t dummy = "123"; | ||
| 31 | 1 | checkTypeHash<gate_cstr_t>(dummy); | |
| 32 | 1 | } | |
| 33 | |||
| 34 | 1 | static void checkWStrTypeHash() | |
| 35 | { | ||
| 36 | static gate_wstr_t dummy = L"123"; | ||
| 37 | 1 | checkTypeHash<gate_wstr_t>(dummy); | |
| 38 | 1 | } | |
| 39 | |||
| 40 | 1 | static void checkDataPtrTypeHash() | |
| 41 | { | ||
| 42 | static int dummy = 123; | ||
| 43 | 1 | void* instance = &dummy; | |
| 44 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | checkTypeHash<void*>(instance); |
| 45 | 1 | } | |
| 46 | |||
| 47 | ✗ | static gate_result_t dummy_func(gate_dataptr_t param) | |
| 48 | { | ||
| 49 | ✗ | return param ? GATE_RESULT_OK : GATE_RESULT_NULLPOINTER; | |
| 50 | } | ||
| 51 | |||
| 52 | 1 | static void checkFuncPtrTypeHash() | |
| 53 | { | ||
| 54 | 1 | gate_funcptr_t instance = &dummy_func; | |
| 55 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | checkTypeHash<gate_funcptr_t>(instance); |
| 56 | 1 | } | |
| 57 | |||
| 58 | 1 | static void checkStringTypeHash() | |
| 59 | { | ||
| 60 | 2 | String instance; | |
| 61 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | checkTypeHash<String>(instance); |
| 62 | 1 | } | |
| 63 | |||
| 64 | 1 | static void checkPropertyTypeHash() | |
| 65 | { | ||
| 66 | { | ||
| 67 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Property instance; |
| 68 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | checkTypeHash<Property>(instance); |
| 69 | } | ||
| 70 | { | ||
| 71 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Property instance = true; |
| 72 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | checkTypeHash<Property>(instance); |
| 73 | } | ||
| 74 | { | ||
| 75 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Property instance = int64_t(123456); |
| 76 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | checkTypeHash<Property>(instance); |
| 77 | } | ||
| 78 | { | ||
| 79 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Property instance = 123.456; |
| 80 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | checkTypeHash<Property>(instance); |
| 81 | } | ||
| 82 | { | ||
| 83 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Property instance("hello"); |
| 84 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | checkTypeHash<Property>(instance); |
| 85 | } | ||
| 86 | { | ||
| 87 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Property instance = Property::createArray(); |
| 88 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | instance.addArrayItem(Property(123.456)); |
| 89 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | checkTypeHash<Property>(instance); |
| 90 | } | ||
| 91 | { | ||
| 92 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Property instance = Property::createObject(); |
| 93 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | instance.addObjectMember("abc", true); |
| 94 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | checkTypeHash<Property>(instance); |
| 95 | } | ||
| 96 | 1 | } | |
| 97 | |||
| 98 | 1 | static void checkObjectTypeHash() | |
| 99 | { | ||
| 100 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | MemStream strm; |
| 101 | 2 | Object instance = strm; | |
| 102 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | checkTypeHash<Object>(instance); |
| 103 | 1 | } | |
| 104 | |||
| 105 | |||
| 106 | struct GATE_API_INTERNAL TestStruct | ||
| 107 | { | ||
| 108 | gate::String member; | ||
| 109 | }; | ||
| 110 | |||
| 111 | namespace gate | ||
| 112 | { | ||
| 113 | template<> | ||
| 114 | struct StructDescriptor<TestStruct> : public DynStructDescriptorBase<TestStruct> | ||
| 115 | { | ||
| 116 | 3 | StructDescriptor() | |
| 117 | 3 | : DynStructDescriptorBase<TestStruct>("TestStruct") | |
| 118 | { | ||
| 119 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | this->addMember(&TestStruct::member, "member"); |
| 120 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | this->updateDescriptor(); |
| 121 | 3 | } | |
| 122 | }; | ||
| 123 | } | ||
| 124 | |||
| 125 | |||
| 126 | 1 | static void checkStructTypeHash() | |
| 127 | { | ||
| 128 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | gate::Struct<TestStruct> s; |
| 129 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | s.member = "Hello World"; |
| 130 | //gate::MutableStruct instance(s); | ||
| 131 | //gate_struct_t* ptrObj = instance.c_impl(); | ||
| 132 | //checkTypeHash<gate_struct_ptr_t>(ptrObj); | ||
| 133 | 2 | gate::ConstStruct instance(s); | |
| 134 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | checkTypeHash<ConstStruct>(instance); |
| 135 | 1 | } | |
| 136 | |||
| 137 |
2/7✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
10 | GATEXX_TEST_UNIT(TypeHashes) |
| 138 | { | ||
| 139 | 2 | checkNumTypeHash<bool_t>(); | |
| 140 | 2 | checkNumTypeHash<int8_t>(); | |
| 141 | 2 | checkNumTypeHash<int16_t>(); | |
| 142 | 2 | checkNumTypeHash<int32_t>(); | |
| 143 | 2 | checkNumTypeHash<int64_t>(); | |
| 144 | 2 | checkNumTypeHash<uint8_t>(); | |
| 145 | 2 | checkNumTypeHash<uint16_t>(); | |
| 146 | 2 | checkNumTypeHash<uint32_t>(); | |
| 147 | 2 | checkNumTypeHash<uint64_t>(); | |
| 148 | 2 | checkNumTypeHash<real32_t>(); | |
| 149 | 2 | checkNumTypeHash<real64_t>(); | |
| 150 | 2 | checkCStrTypeHash(); | |
| 151 | 2 | checkWStrTypeHash(); | |
| 152 | 2 | checkDataPtrTypeHash(); | |
| 153 | 2 | checkFuncPtrTypeHash(); | |
| 154 | 2 | checkStringTypeHash(); | |
| 155 | 2 | checkPropertyTypeHash(); | |
| 156 | 2 | checkObjectTypeHash(); | |
| 157 | 2 | checkStructTypeHash(); | |
| 158 | |||
| 159 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
2 | checkTypeHash(*Guid::generate().c_impl()); |
| 160 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | checkTypeHash(static_cast<gate_date_t const&>(Date())); |
| 161 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | checkTypeHash(static_cast<gate_daytime_t const&>(DayTime())); |
| 162 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | checkTypeHash(static_cast<gate_datetime_t const&>(DateTime())); |
| 163 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | checkTypeHash(static_cast<gate_time_t const&>(Time())); |
| 164 | 2 | } | |
| 165 | |||
| 166 |
2/7✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
10 | GATEXX_TEST_UNIT(Hashes) |
| 167 | { | ||
| 168 | 2 | int data = 42; | |
| 169 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
4 | HashGenerator hg; |
| 170 | |||
| 171 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
2 | GATEXX_TEST_CHECK_NOTHROW(hg.update(&data, sizeof(data))); |
| 172 | |||
| 173 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
2 | GATEXX_TEST_CHECK_NOTHROW(hg.finish()); |
| 174 | 2 | } | |
| 175 | |||
| 176 |