|
| 1 | +#include <library/cpp/testing/unittest/registar.h> |
| 2 | + |
| 3 | +#include <ydb/core/scheme/scheme_tablecell.h> |
| 4 | +#include <ydb/core/scheme/scheme_type_registry.h> |
| 5 | + |
| 6 | +extern "C" { |
| 7 | +#include "postgres.h" |
| 8 | +#include "catalog/pg_type_d.h" |
| 9 | +} |
| 10 | + |
| 11 | +namespace NKikimr { |
| 12 | +namespace NTable { |
| 13 | + |
| 14 | +Y_UNIT_TEST_SUITE(PgTest) { |
| 15 | + |
| 16 | + Y_UNIT_TEST(DumpIntCells) { |
| 17 | + NScheme::TTypeRegistry typeRegistry; |
| 18 | + |
| 19 | + i64 intVal = 55555; |
| 20 | + |
| 21 | + { |
| 22 | + TCell cell((const char *)&intVal, sizeof(i64)); |
| 23 | + NScheme::TTypeInfo typeInfo(NScheme::TInt64::TypeId); |
| 24 | + |
| 25 | + TString printRes = DbgPrintCell(cell, typeInfo, typeRegistry); |
| 26 | + UNIT_ASSERT_STRINGS_EQUAL(printRes, "Int64 : 55555"); |
| 27 | + } |
| 28 | + |
| 29 | + { |
| 30 | + NScheme::TTypeInfo pgTypeInfo(NScheme::NTypeIds::Pg, NPg::TypeDescFromPgTypeId(INT8OID)); |
| 31 | + auto desc = pgTypeInfo.GetTypeDesc(); |
| 32 | + auto res = NPg::PgNativeBinaryFromNativeText(Sprintf("%u", intVal), desc); |
| 33 | + UNIT_ASSERT_C(!res.Error, *res.Error); |
| 34 | + TString binary = res.Str; |
| 35 | + TCell pgCell((const char*)binary.data(), binary.size()); |
| 36 | + |
| 37 | + TString printRes = DbgPrintCell(pgCell, pgTypeInfo, typeRegistry); |
| 38 | + UNIT_ASSERT_STRINGS_EQUAL(printRes, "pgint8 : 55555"); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + Y_UNIT_TEST(DumpStringCells) { |
| 43 | + NScheme::TTypeRegistry typeRegistry; |
| 44 | + |
| 45 | + char strVal[] = "This is the value"; |
| 46 | + |
| 47 | + { |
| 48 | + TCell cell((const char*)&strVal, sizeof(strVal) - 1); |
| 49 | + NScheme::TTypeInfo typeInfo(NScheme::TString::TypeId); |
| 50 | + |
| 51 | + TString printRes = DbgPrintCell(cell, typeInfo, typeRegistry); |
| 52 | + UNIT_ASSERT_STRINGS_EQUAL(printRes, TStringBuilder() << "String : " << strVal); |
| 53 | + } |
| 54 | + |
| 55 | + { |
| 56 | + NScheme::TTypeInfo pgTypeInfo(NScheme::NTypeIds::Pg, NPg::TypeDescFromPgTypeId(TEXTOID)); |
| 57 | + auto desc = pgTypeInfo.GetTypeDesc(); |
| 58 | + auto res = NPg::PgNativeBinaryFromNativeText(strVal, desc); |
| 59 | + UNIT_ASSERT_C(!res.Error, *res.Error); |
| 60 | + TString binary = res.Str; |
| 61 | + TCell pgCell((const char*)binary.data(), binary.size()); |
| 62 | + |
| 63 | + TString printRes = DbgPrintCell(pgCell, pgTypeInfo, typeRegistry); |
| 64 | + UNIT_ASSERT_STRINGS_EQUAL(printRes, TStringBuilder() << "pgtext : " << strVal); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +} |
| 70 | +} |
0 commit comments