#include "accessors.h" #include #include #include #include class TAccessorsTest: public TTestBase { UNIT_TEST_SUITE(TAccessorsTest); UNIT_TEST(TestAccessors); UNIT_TEST_SUITE_END(); private: template void TestRead(const T& t, const char* comm) { const char* beg = (const char*)NAccessors::Begin(t); const char* end = (const char*)NAccessors::End(t); long sz = NAccessors::Size(t) * sizeof(typename TMemoryTraits::TElementType); UNIT_ASSERT_VALUES_EQUAL_C(end - beg, sz, comm); } template void TestWrite(const char* comm) { typename TMemoryTraits::TElementType val[4] = {'t', 'e', 's', 't'}; T t; NAccessors::Init(t); NAccessors::Reserve(t, 6); size_t sz = NAccessors::Size(t); UNIT_ASSERT_VALUES_EQUAL_C(0u, sz, comm); NAccessors::Append(t, 'a'); sz = NAccessors::Size(t); UNIT_ASSERT_VALUES_EQUAL_C(1u, sz, comm); NAccessors::Append(t, val, val + 4); sz = NAccessors::Size(t); UNIT_ASSERT_VALUES_EQUAL_C(5u, sz, comm); NAccessors::Clear(t); sz = NAccessors::Size(t); UNIT_ASSERT_VALUES_EQUAL_C(0u, sz, comm); } void TestAccessors() { TestRead('a', "char"); TestRead(1, "int"); int t[4] = {0, 1, 2, 3}; TestRead(t, "int[4]"); TStringBuf sbuf = "test"; TestRead(sbuf, "TStringBuf"); TUtf16String wtr; wtr.resize(10, 1024); TestRead(wtr, "TUtf16String"); TBuffer buf; buf.Resize(30); TestRead(buf, "TBuffer"); TVector vec(10, 100); TestRead(vec, "TVector"); TestWrite("TString"); TestWrite>("TVector"); TestWrite("TBuffer"); TestWrite>("TVector"); TestWrite("TUtf16String"); std::array sarr; NAccessors::Init(sarr); NAccessors::Clear(sarr); std::array carr; NAccessors::Init(carr); NAccessors::Clear(carr); TestRead(carr, "std::array"); } }; UNIT_TEST_SUITE_REGISTRATION(TAccessorsTest)