FIXTURE_TEST_CASE(View_Parameter_View, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 {}; view X#1 <T t> {}; view v#1 <X v> {}", "v", 1 ); REQUIRE_EQ ( 1u, v . Parameters () . Count () ); REQUIRE_EQ ( (uint32_t)eView, v . Parameters () . Get ( 0 ) -> type ); REQUIRE_EQ ( (const void *) GetView ( 0 ) . m_self, v . Parameters () . Get ( 0 ) -> u . obj ); }
// Parameters FIXTURE_TEST_CASE(View_Parameter_Table, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 {}; view v#1 <T t> {}", "v" ); REQUIRE_EQ ( 1u, v . Parameters () . Count () ); REQUIRE_EQ ( (uint32_t)eTable, v . Parameters () . Get ( 0 ) -> type ); REQUIRE_EQ ( (const void *) GetTable ( 0 ), v . Parameters () . Get ( 0 ) -> u . obj ); }
void wrapTest(void (*test)()) { REQUIRE_EQ(tfs_mkfs(DEFAULT_DISK_NAME, DEFAULT_DISK_SIZE), TFS_SUCCESS); REQUIRE_EQ(tfs_mount(DEFAULT_DISK_NAME), TFS_SUCCESS); test(); REQUIRE_EQ(tfs_unmount(), TFS_SUCCESS); }
FIXTURE_TEST_CASE(Version_2_Empty_Source, AST_Fixture) { AST * ast = MakeAst ( "version 2; table t#1 {};" ); REQUIRE_NOT_NULL ( ast ); REQUIRE_EQ ( ( int ) PT_SCHEMA_2_0, ast -> GetTokenType () ); REQUIRE_EQ ( 2u, ast -> ChildrenCount () ); REQUIRE_EQ ( ( int ) PT_EMPTY, ast -> GetChild ( 0 ) -> GetTokenType () ); // declarations in a list REQUIRE_EQ ( ( int ) PT_VERSION_2, ast -> GetChild ( 1 ) -> GetTokenType () ); }
FIXTURE_TEST_CASE(View_Id, AST_View_Fixture) { // both version are registered ViewAccess v1 = ParseView ( "version 2; table T#1 {}; view v#1 <T t> {}; view v#2 <T t> {}", "v" ); ViewAccess v2 = GetView ( 1 ); REQUIRE_EQ ( 2u, VectorLength ( & GetSchema () -> view ) ); REQUIRE_EQ ( 0u, v1 . Id () ); REQUIRE_EQ ( 1u, v2 . Id () ); }
FIXTURE_TEST_CASE(View_Production_ForwardReference_DefinedAsProduction, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 {}; view V#1 <T v> { U16 a = p; U8 p = 1; }", "V" ); REQUIRE_EQ ( 2u, v . Productions () . Count () ); const SProduction * a = v . Productions () . Get ( 0 ); VerifySymExpr ( a -> expr, eProdExpr, "p", eProduction ); // once defined, p is not virtual anymore REQUIRE_EQ ( 0u, v . VirtualProductions () . Count () ); }
FIXTURE_TEST_CASE(View_Column_Reference, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 {}; view W#1 <T v> { column U8 c1 = 1; column U8 c2 = c1; }", "W" ); REQUIRE_EQ ( 2u, v . Columns () . Count () ); const SColumn & c = * v . Columns () . Get ( 1 ); REQUIRE_NOT_NULL ( c . name ); REQUIRE_EQ ( string ("c2"), ToCppString ( c . name -> name ) ); REQUIRE_NOT_NULL ( c . read ); REQUIRE_EQ ( ( uint32_t ) eColExpr, c . read -> var ); }
FIXTURE_TEST_CASE(View_NewerMinorVersion, AST_View_Fixture) { // older minor version is replaced ViewAccess v = ParseView ( "version 2; table T#1 {}; view v#1.1 <T t> {}; view v#1.2 <T t> {}", "v" ); REQUIRE_EQ ( 1u, VectorLength ( & GetSchema () -> view ) ); REQUIRE_EQ ( Version ( 1, 2 ), v . Version () ); REQUIRE_EQ ( 1u, VectorLength ( & GetSchema () -> vname ) ); REQUIRE_EQ ( 1u, v . Overloads () . Count () ); }
void verifyFile(fileDescriptor FD, int size) { initializeFile(FD, size); int ndx; char byte; for (ndx = 0; ndx < size; ++ndx) { REQUIRE_EQ(tfs_readByte(FD, &byte), TFS_SUCCESS); REQUIRE_EQ(byte, '0' + (ndx % 7)); } }
FIXTURE_TEST_CASE(View_Join_Shorthand, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2;" "table T1#1 { column I64 c1; };" "table T2#1 { column U8 c2; };" "view X#1 <T1 t1, T2 t2> { column U8 c3 = t2 [ t1 . c1 ] . c2; }; ", "X" ); REQUIRE_EQ ( 1u, v . Columns () . Count () ); const SColumn & c = * v . Columns () . Get ( 0 ); REQUIRE_NOT_NULL ( c . name ); REQUIRE_EQ ( string ("c3"), ToCppString ( c . name -> name ) ); REQUIRE_NOT_NULL ( c . read ); REQUIRE_EQ ( ( uint32_t ) eMembExpr, c . read -> var ); const SMembExpr * expr = reinterpret_cast < const SMembExpr * > ( c . read ); REQUIRE_EQ ( v . m_self, expr -> view ); REQUIRE_EQ ( 1u, expr -> paramId ); // t2 REQUIRE_EQ ( string("c2"), ToCppString ( expr -> member -> name ) ); REQUIRE_NOT_NULL ( expr -> rowId ); const SMembExpr * rowId = reinterpret_cast < const SMembExpr * > ( expr -> rowId ); REQUIRE_EQ ( v . m_self, rowId -> view ); REQUIRE_EQ ( 0u, rowId -> paramId ); // t1 REQUIRE_EQ ( string("c1"), ToCppString ( rowId -> member -> name ) ); REQUIRE_NULL ( rowId -> rowId ); }
FIXTURE_TEST_CASE(View_Column, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 {}; view W#1 <T v> { column U8 c = 1; }", "W" ); REQUIRE_EQ ( 1u, v . Columns () . Count () ); const SColumn & c = * v . Columns () . Get ( 0 ); REQUIRE_NOT_NULL ( c . name ); REQUIRE_EQ ( ( uint32_t ) eColumn, c . name -> type ); REQUIRE_NOT_NULL ( c . read ); REQUIRE_EQ ( ( uint32_t ) eConstExpr, c . read -> var ); REQUIRE_EQ ( string ("c"), ToCppString ( c . name -> name ) ); REQUIRE_NULL ( c . validate ); REQUIRE_NULL ( c . limit ); REQUIRE_NULL ( c . ptype ); REQUIRE_EQ ( U8_id, c . td . type_id ); REQUIRE_EQ ( 1u, c . td . dim); REQUIRE_EQ ( 1u, c . cid . ctx ); // T;s contextId is 0, W's is 1 REQUIRE_EQ ( 0u, c . cid . id ); REQUIRE ( ! c . dflt ); REQUIRE ( c . read_only ); REQUIRE ( ! c . simple ); REQUIRE_EQ ( ( const void * ) v . ColumnNames () . Get ( 0 ), c . name -> u . obj ); }
void testMount() { printf("testing tfs_mount\n"); printf("non-existant file\n"); REQUIRE_EQ(tfs_mount(FILE_NOT_EXISTS), TFS_EACCESS); printf("valid file\n"); REQUIRE_EQ(tfs_mount(FILE_VALID), TFS_SUCCESS); tfs_unmount(); printf("valid file, then non-existant file\n"); REQUIRE_EQ(tfs_mount(FILE_VALID), TFS_SUCCESS); REQUIRE_EQ(tfs_mount(FILE_NOT_EXISTS), TFS_EONEFS); tfs_unmount(); printf("valid file, then valid file\n"); REQUIRE_EQ(tfs_mount(FILE_VALID), TFS_SUCCESS); REQUIRE_EQ(tfs_mount(FILE_VALID), TFS_EONEFS); tfs_unmount(); printf("invalid file\n"); REQUIRE_EQ(tfs_mount(FILE_INVALID), TFS_ENOTFS); printf("invalid file, then valid file\n"); REQUIRE_EQ(tfs_mount(FILE_INVALID), TFS_ENOTFS); REQUIRE_EQ(tfs_mount(FILE_VALID), TFS_SUCCESS); tfs_unmount(); }
FIXTURE_TEST_CASE(View_OneTable_NoParents, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 {}; view v#1 <T t> {}", "v" ); REQUIRE_NULL ( v . m_self -> name -> dad ); REQUIRE_EQ ( ( uint32_t ) eView, v . m_self -> name -> type ); // verify entry in the container of (overloaded on version) view names REQUIRE_EQ ( 1u, VectorLength ( & GetSchema () -> vname ) ); REQUIRE_EQ ( 1u, v . Overloads () . Count () ); REQUIRE_EQ ( v . GetOverloads (), ( const SNameOverload * ) VectorGet ( & GetSchema () -> vname, 0 ) ); }
FIXTURE_TEST_CASE(View_Parents_ProductionsInherited, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 {}; " "view V#1 <T t> { U8 v = 1; }; " "view X#1 <T t> = V<t> { U8 _v = v; }", "X", 1 ); // v does not count as X's production but is accessible REQUIRE_EQ ( 1u, v . Productions () . Count () ); REQUIRE_EQ ( string ("_v"), ToCppString ( v . Productions () . Get ( 0 ) -> name -> name ) ); }
FIXTURE_TEST_CASE(View_OlderMajorVersion, AST_View_Fixture) { // both version are registered ViewAccess v1 = ParseView ( "version 2; table T#1 {}; view v#2 <T t> {}; view v#1 <T t> {}", "v" ); ViewAccess v2 = GetView ( 1 ); REQUIRE_EQ ( 2u, VectorLength ( & GetSchema () -> view ) ); REQUIRE_EQ ( Version ( 2 ), v1 . Version () ); REQUIRE_EQ ( Version ( 1 ), v2 . Version () ); // 1 entry in the table of view overloads, the entry points to the 2 versions of the view, the views point back REQUIRE_EQ ( 1u, VectorLength ( & GetSchema () -> vname ) ); REQUIRE_EQ ( 2u, v1 . Overloads () . Count () ); }
FIXTURE_TEST_CASE(View_Parents_ColumnsInherited, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 {}; " "view V#1 <T t> { column U8 v = 1; }; " "view W#1 <T t> { column U16 w = 1; }; " "view X#1 <T t> = V<t>, W<t> {}", "X", 2 ); REQUIRE_EQ ( 2u, v . ColumnNames () . Count () ); // v and w are seen as X's columns REQUIRE_EQ ( string ("v"), ToCppString ( v . ColumnNames () . Get ( 0 ) -> name -> name ) ); REQUIRE_EQ ( string ("w"), ToCppString ( v . ColumnNames () . Get ( 1 ) -> name -> name ) ); }
FIXTURE_TEST_CASE(View_Column_Context, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 {};" " view V#1 <T t> {}" " view W#1 <T t> { column U8 c1 = 1; column U8 c2 = 2; }", "W", 1 ); const SNameOverload * ovl = v . ColumnNames () . Get ( 0 ); REQUIRE_NOT_NULL ( ovl ); REQUIRE_EQ ( 2u, ovl -> cid . ctx ); // W'1 contextId is 2 REQUIRE_EQ ( 0u, ovl -> cid . id ); const SColumn * col = v . Columns () . Get ( 0 ); REQUIRE_NOT_NULL ( col ); REQUIRE_EQ ( ovl -> cid . ctx, col -> cid . ctx ); REQUIRE_EQ ( ovl -> cid . id, col -> cid . id ); ovl = v . ColumnNames () . Get ( 1 ); REQUIRE_NOT_NULL ( ovl ); REQUIRE_EQ ( 2u, ovl -> cid . ctx ); REQUIRE_EQ ( 1u, ovl -> cid . id ); col = v . Columns () . Get ( 1 ); REQUIRE_NOT_NULL ( col ); REQUIRE_EQ ( ovl -> cid . ctx, col -> cid . ctx ); REQUIRE_EQ ( ovl -> cid . id, col -> cid . id ); }
FIXTURE_TEST_CASE(View_Parents_VirtualProductionDefined, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 {}; " "view V#1 <T t> { U8 p = v; }; " "view X#1 <T t> = V<t> { U8 v = 1; }", "X", 1 ); REQUIRE_EQ ( 1u, v . Productions () . Count () ); REQUIRE_EQ ( string ("v"), ToCppString ( v . Productions () . Get ( 0 ) -> name -> name ) ); // verify p and its reference to v const SProduction * p = GetView ( 0 ) . Productions () . Get ( 0 ); REQUIRE_NOT_NULL ( p ); VerifySymExpr ( p -> expr, eFwdExpr, "v", eVirtual ); }
FIXTURE_TEST_CASE(View_ForwardReference, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 {}; view V#1 <T v> { column U16 a = p; column U8 p = 1; }", "V" ); REQUIRE_EQ ( 2u, v . Columns () . Count () ); const SColumn * a = v . Columns () . Get ( 0 ); VerifySymExpr ( a -> read, eColExpr, "p", eColumn ); }
FIXTURE_TEST_CASE(View_Parents_InheritedVirtualProduction, AST_View_Fixture) { ViewAccess t = ParseView ( "version 2; table T#1 {}; " "view granddad #1 <T t> { U8 a = v; }; " "view dad #1 <T t> = granddad<t> { U8 b = v; }; " "view t #1 <T t> = dad<t> { }", "t", 2 ); // verify overrides // dad ViewAccess dad = GetView ( 1 ); REQUIRE_EQ ( 1u, dad . Overrides () . Count () ); // inherits from granddad VdbVector < const KSymbol > dadOvr ( dad . Overrides () . Get ( 0 ) -> by_parent ); REQUIRE_EQ ( 1u, dadOvr . Count () ); // 1 override copied from granddad // t REQUIRE_EQ ( 2u, t . Overrides () . Count () ); // v inherits from dad and granddad VdbVector < const KSymbol > tDadOvr ( t . Overrides () . Get ( 0 ) -> by_parent ); REQUIRE_EQ ( 1u, tDadOvr . Count () ); // 1 override copied from granddad REQUIRE_EQ ( string ( "v" ), ToCppString ( tDadOvr . Get ( 0 ) -> name ) ); VdbVector < const KSymbol > tGdadOvr ( t . Overrides () . Get ( 1 ) -> by_parent ); REQUIRE_EQ ( 0u, tGdadOvr . Count () ); // no overrides copied from granddad // v is not resolved in t REQUIRE_EQ ( 0u, t . VirtualProductions () . Count () ); }
FIXTURE_TEST_CASE(View_Parameter_VersionedView, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 {}; " "view a:V#1 <T t> {}; " "view a:V#2 <T t> {}; " "view v#1 <a:V#2 v> {}", "v", 2 ); REQUIRE_EQ ( (const void*)GetView ( 1 ) . m_self, v . Parameters () . Get ( 0 ) -> u . obj ); }
void initializeFile(fileDescriptor FD, int size) { char* buffer = (char*)malloc(size * sizeof(char)); int ndx; for (ndx = 0; ndx < size; ++ndx) { buffer[ndx] = '0' + (ndx % 7); } REQUIRE_EQ(tfs_writeFile(FD, buffer, size), TFS_SUCCESS); free(buffer); }
FIXTURE_TEST_CASE(View_Column_ReferenceToParamViewsColumn, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 { U8 c1 = 1; };" " view V#1 <T t> { column U8 c2 = t . c1; }" " view W#1 <V v> { column U8 c3 = v . c2; }", "W", 1 ); const SColumn & c = * v . Columns () . Get ( 0 ); REQUIRE_NOT_NULL ( c . read ); REQUIRE_EQ ( ( uint32_t ) eMembExpr, c . read -> var ); }
void testNestedDirCreationAndDeletion() { printf("testing directory creation and deletion\n"); printf("creating directories 'a', 'b', and 'c'\n"); REQUIRE_EQ(tfs_createDir("a"), TFS_SUCCESS); REQUIRE_EQ(tfs_createDir("b"), TFS_SUCCESS); REQUIRE_EQ(tfs_createDir("c"), TFS_SUCCESS); printf("creating nested directories 'a/a', 'a/b', and 'a/c'\n"); REQUIRE_EQ(tfs_createDir("a/a"), TFS_SUCCESS); REQUIRE_EQ(tfs_createDir("a/b"), TFS_SUCCESS); REQUIRE_EQ(tfs_createDir("a/c"), TFS_SUCCESS); printf("creating nested files 'a/a/a', 'a/a/b', and 'a/a/c'\n"); REQUIRE_GT(tfs_openFile("a/a/a"), -1); REQUIRE_GT(tfs_openFile("a/a/b"), -1); REQUIRE_GT(tfs_openFile("a/a/c"), -1); printf("listing disk contents\n"); REQUIRE_GT(tfs_listDisk(), -1); printf("recursively deleting directory 'a/a'\n"); REQUIRE_GT(tfs_removeAll("a/a"), -1); printf("listing disk contents\n"); REQUIRE_GT(tfs_listDisk(), -1); printf("recursively deleting directory '/'\n"); REQUIRE_GT(tfs_removeAll(""), -1); printf("listing disk contents\n"); REQUIRE_GT(tfs_listDisk(), -1); }
void testIncrementalWriteAndRead() { printf("testing incremental file write and read\n"); printf("creating file 'file'\n"); fileDescriptor FD = tfs_openFile("file"); REQUIRE_GT(FD, -1); int ndx; // Initialize file. for (ndx = 0; ndx < 300; ++ndx) { REQUIRE_EQ(tfs_writeByte(FD, '0' + (ndx % 7)), TFS_SUCCESS); } // Jump to file start. REQUIRE_EQ(tfs_seek(FD, 0), TFS_SUCCESS); // Validate file content. char byte; for (ndx = 0; ndx < 300; ++ndx) { REQUIRE_EQ(tfs_readByte(FD, &byte), TFS_SUCCESS); REQUIRE_EQ(byte, '0' + (ndx % 7)); } }
FIXTURE_TEST_CASE(View_Parents_VirtualProductionDefinedAcrossParents, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 {}; " "view V#1 <T t> { column U8 c = v; }; " "view W#1 <T t> { U8 v = 1; }; " "view X#1 <T t> = V<t>, W<t> {}", "X", 2 ); REQUIRE_EQ ( 0u, v . Productions () . Count () ); // verify c and its reference to W.v const SColumn * p = GetView ( 0 ) . Columns () . Get ( 0 ); REQUIRE_NOT_NULL ( p ); VerifySymExpr ( p -> read, eFwdExpr, "v", eVirtual ); }
void testBulkWriteAndRead() { printf("testing bulk file write and read\n"); printf("creating file 'file'\n"); fileDescriptor FD = tfs_openFile("file"); REQUIRE_GT(FD, -1); verifyFile(FD, 1); verifyFile(FD, 252); verifyFile(FD, 300); verifyFile(FD, 600); char hugeBuffer[DEFAULT_DISK_SIZE * 252]; REQUIRE_EQ(tfs_writeFile(FD, hugeBuffer, DEFAULT_DISK_SIZE * 252), TFS_ESPACE); }
FIXTURE_TEST_CASE(View_Column_ReferenceToParamTablesColumn, AST_View_Fixture) { // introducing member expressions! ViewAccess v = ParseView ( "version 2; table T#1 { column U8 c1 = 1; }; view W#1 <T t0, T t1> { column U8 c2 = t1 . c1; }", "W" ); REQUIRE_EQ ( 1u, v . Columns () . Count () ); const SColumn & c = * v . Columns () . Get ( 0 ); REQUIRE_NOT_NULL ( c . name ); REQUIRE_EQ ( string ("c2"), ToCppString ( c . name -> name ) ); REQUIRE_NOT_NULL ( c . read ); REQUIRE_EQ ( ( uint32_t ) eMembExpr, c . read -> var ); const SMembExpr * expr = reinterpret_cast < const SMembExpr * > ( c . read ); REQUIRE_EQ ( v .m_self, expr -> view ); REQUIRE_EQ ( 1u, expr -> paramId ); REQUIRE_EQ ( string("c1"), ToCppString ( expr -> member -> name ) ); }
FIXTURE_TEST_CASE(View_Parents_OverloadingParentsColumn, AST_View_Fixture) { ViewAccess v = ParseView ( "version 2; table T#1 {}; " "view W#1 <T t> { column U8 c = 1; }; " "view X#1 <T t> = W<t> { column U16 c = 2; }", "X", 1 ); ViewAccess dad = GetView ( 0 ); REQUIRE_EQ ( 1u, v . Columns () . Count () ); REQUIRE_EQ ( 1u, v . ColumnNames () . Count () ); const SNameOverload * ovl = v . ColumnNames () . Get ( 0 ); REQUIRE_NOT_NULL ( ovl ); REQUIRE_EQ ( string ("c"), ToCppString ( ovl -> name -> name ) ); REQUIRE_EQ ( 1u, ovl -> cid . ctx ); // inherited from W whose contexId is 1 REQUIRE_EQ ( 0u, ovl -> cid . id ); VdbVector < SColumn > names ( ovl -> items ); REQUIRE_EQ ( 2u, names . Count () ); REQUIRE_EQ ( dad . Columns () . Get ( 0 ), names . Get ( 0 ) ); REQUIRE_EQ ( v . Columns () . Get ( 0 ), names . Get ( 1 ) ); }
void testDirCreationAndDeletion() { printf("testing directory creation and deletion\n"); printf("creating directories 'a', 'b', and 'c'\n"); REQUIRE_EQ(tfs_createDir("a"), TFS_SUCCESS); REQUIRE_EQ(tfs_createDir("b"), TFS_SUCCESS); REQUIRE_EQ(tfs_createDir("c"), TFS_SUCCESS); printf("listing disk contents\n"); REQUIRE_GT(tfs_listDisk(), -1); printf("deleting directories 'a', 'b', and 'c'\n"); REQUIRE_EQ(tfs_removeDir("a"), TFS_SUCCESS); REQUIRE_EQ(tfs_removeDir("b"), TFS_SUCCESS); REQUIRE_EQ(tfs_removeDir("c"), TFS_SUCCESS); printf("listing disk contents\n"); REQUIRE_GT(tfs_listDisk(), -1); }