Moved typemapping test code to its own unit so it is clearer that the tests exist
This commit is contained in:
parent
c13bbde2e4
commit
daf9536bed
2 changed files with 71 additions and 59 deletions
|
|
@ -170,62 +170,3 @@ TEST(IndentationConfig, tab8indent4false_level2)
|
|||
ASSERT_EQ(result, " ");
|
||||
}
|
||||
|
||||
|
||||
class TypeMappingsTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
def_str_type = "std::string";
|
||||
int4str = "int";
|
||||
int8str = "long long";
|
||||
tm = TypeMappings( {
|
||||
{ Pgsql::int4_oid, int4str },
|
||||
{ Pgsql::int8_oid, int8str }
|
||||
});
|
||||
tm.setDefaultStringType(def_str_type);
|
||||
tm.setDefaultContainerType("std::vector<%1>");
|
||||
}
|
||||
|
||||
// void TearDown() override {}
|
||||
|
||||
QString def_str_type;
|
||||
QString int4str;
|
||||
QString int8str;
|
||||
TypeMappings tm;
|
||||
};
|
||||
|
||||
TEST_F(TypeMappingsTest, defStringType)
|
||||
{
|
||||
QString result = tm.getTypeForOid(Pgsql::float4_oid);
|
||||
ASSERT_EQ(result, def_str_type);
|
||||
}
|
||||
|
||||
TEST_F(TypeMappingsTest, int4Type)
|
||||
{
|
||||
QString result = tm.getTypeForOid(Pgsql::int4_oid);
|
||||
ASSERT_EQ(result, int4str);
|
||||
}
|
||||
|
||||
TEST_F(TypeMappingsTest, int4overideType)
|
||||
{
|
||||
tm.set(Pgsql::int4_oid, "QString");
|
||||
QString result = tm.getTypeForOid(Pgsql::int4_oid);
|
||||
ASSERT_EQ(result, "QString");
|
||||
}
|
||||
|
||||
// Need catalogue for the next test
|
||||
// Maybe we should mock this !?
|
||||
TEST_F(TypeMappingsTest, int4arrayType)
|
||||
{
|
||||
auto types= std::make_shared<PgTypeContainer>();
|
||||
PgType int4arr;
|
||||
int4arr.oid = Pgsql::int4_array_oid;
|
||||
int4arr.elem = Pgsql::int4_oid;
|
||||
types->add(int4arr);
|
||||
|
||||
tm.setTypes(types);
|
||||
|
||||
QString result = tm.getTypeForOid(Pgsql::int4_array_oid);
|
||||
ASSERT_EQ(result, "std::vector<int>");
|
||||
}
|
||||
|
||||
|
|
|
|||
71
tests/pglabtests/tst_TypeMappings.cpp
Normal file
71
tests/pglabtests/tst_TypeMappings.cpp
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
//#include <QRegularExpression>
|
||||
#include "PgType.h"
|
||||
#include "PgTypeContainer.h"
|
||||
//#include "PrintTo_Qt.h"
|
||||
//#include "codebuilder/IndentationConfig.h"
|
||||
#include "codebuilder/TypeMappings.h"
|
||||
#include "Pgsql_oids.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
||||
class TypeMappingsTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
def_str_type = "std::string";
|
||||
int4str = "int";
|
||||
int8str = "long long";
|
||||
tm = TypeMappings( {
|
||||
{ Pgsql::int4_oid, int4str },
|
||||
{ Pgsql::int8_oid, int8str }
|
||||
});
|
||||
tm.setDefaultStringType(def_str_type);
|
||||
tm.setDefaultContainerType("std::vector<%1>");
|
||||
}
|
||||
|
||||
// void TearDown() override {}
|
||||
|
||||
QString def_str_type;
|
||||
QString int4str;
|
||||
QString int8str;
|
||||
TypeMappings tm;
|
||||
};
|
||||
|
||||
TEST_F(TypeMappingsTest, defStringType)
|
||||
{
|
||||
QString result = tm.getTypeForOid(Pgsql::float4_oid);
|
||||
ASSERT_EQ(result, def_str_type);
|
||||
}
|
||||
|
||||
TEST_F(TypeMappingsTest, int4Type)
|
||||
{
|
||||
QString result = tm.getTypeForOid(Pgsql::int4_oid);
|
||||
ASSERT_EQ(result, int4str);
|
||||
}
|
||||
|
||||
TEST_F(TypeMappingsTest, int4overideType)
|
||||
{
|
||||
tm.set(Pgsql::int4_oid, "QString");
|
||||
QString result = tm.getTypeForOid(Pgsql::int4_oid);
|
||||
ASSERT_EQ(result, "QString");
|
||||
}
|
||||
|
||||
// Need catalogue for the next test
|
||||
// Maybe we should mock this !?
|
||||
TEST_F(TypeMappingsTest, int4arrayType)
|
||||
{
|
||||
auto types= std::make_shared<PgTypeContainer>();
|
||||
PgType int4arr;
|
||||
int4arr.oid = Pgsql::int4_array_oid;
|
||||
int4arr.elem = Pgsql::int4_oid;
|
||||
types->add(int4arr);
|
||||
|
||||
tm.setTypes(types);
|
||||
|
||||
QString result = tm.getTypeForOid(Pgsql::int4_array_oid);
|
||||
ASSERT_EQ(result, "std::vector<int>");
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue