From 58924ad8934263cbc67933860762a618f06d8c4c Mon Sep 17 00:00:00 2001 From: oleks Date: Thu, 6 Mar 2014 13:11:36 +0100 Subject: [PATCH 1/5] Reorganising Splitting the tests into individual functions. First additions to the tests. --- src/tightdb/objc/test/dynamic_table.m | 124 +++++++++++++++++--------- 1 file changed, 80 insertions(+), 44 deletions(-) diff --git a/src/tightdb/objc/test/dynamic_table.m b/src/tightdb/objc/test/dynamic_table.m index 0b3f882436..3fa9911450 100644 --- a/src/tightdb/objc/test/dynamic_table.m +++ b/src/tightdb/objc/test/dynamic_table.m @@ -63,83 +63,119 @@ - (void)testTable STFail(@"First not zero"); if ([_table getIntInColumn:1 atRow:ndx] != 10) STFail(@"Second not 10"); - +} + +-(void)testAppendRowsIntColumn +{ // Add row using object literate - TightdbTable* _table2 = [[TightdbTable alloc] init]; - [_table2 addColumnWithType:tightdb_Int andName:@"first"]; - if (![_table2 appendRow:@[ @1 ]]) + TightdbTable* t = [[TightdbTable alloc] init]; + [t addColumnWithType:tightdb_Int andName:@"first"]; + if (![t appendRow:@[ @1 ]]) STFail(@"Impossible!"); - if ([_table2 count] != 1) + if ([t count] != 1) STFail(@"Excepted 1 row"); - if (![_table2 appendRow:@[ @2 ]]) + if (![t appendRow:@[ @2 ]]) STFail(@"Impossible!"); - if ([_table2 count] != 2) + if ([t count] != 2) STFail(@"Excepted 2 rows"); - if ([_table2 getIntInColumn:0 atRow:0] != 1) + if ([t getIntInColumn:0 atRow:0] != 1) STFail(@"Value 1 excepted"); - if ([_table2 getIntInColumn:0 atRow:1] != 2) + if ([t getIntInColumn:0 atRow:1] != 2) STFail(@"Value 2 excepted"); - if ([_table2 appendRow:@[@"Hello"]]) + if ([t appendRow:@[@"Hello"]]) STFail(@"Wrong type"); - if ([_table2 appendRow:@[@1, @"Hello"]]) + if ([t appendRow:@[@1, @"Hello"]]) STFail(@"Wrong number of columns"); +} - TightdbTable* _table3 = [[TightdbTable alloc] init]; - [_table3 addColumnWithType:tightdb_Int andName:@"first"]; - [_table3 addColumnWithType:tightdb_String andName:@"second"]; - if (![_table3 appendRow:@[@1, @"Hello"]]) +-(void)testAppendRowsIntStringColumns +{ + TightdbTable* t = [[TightdbTable alloc] init]; + [t addColumnWithType:tightdb_Int andName:@"first"]; + [t addColumnWithType:tightdb_String andName:@"second"]; + if (![t appendRow:@[@1, @"Hello"]]) STFail(@"appendRow 1"); - if ([_table3 count] != 1) + if ([t count] != 1) STFail(@"1 row expected"); - if ([_table3 getIntInColumn:0 atRow:0] != 1) + if ([t getIntInColumn:0 atRow:0] != 1) STFail(@"Value 1 excepted"); - if (![[_table3 getStringInColumn:1 atRow:0] isEqualToString:@"Hello"]) + if (![[t getStringInColumn:1 atRow:0] isEqualToString:@"Hello"]) STFail(@"Value 'Hello' excepted"); - if ([_table3 appendRow:@[@1, @2]]) + if ([t appendRow:@[@1, @2]]) STFail(@"appendRow 2"); +} - TightdbTable* _table4 = [[TightdbTable alloc] init]; - [_table4 addColumnWithType:tightdb_Double andName:@"first"]; - if (![_table4 appendRow:@[@3.14]]) /* double is default */ +-(void)testAppendRowsDoubleColumn +{ + TightdbTable* t = [[TightdbTable alloc] init]; + [t addColumnWithType:tightdb_Double andName:@"first"]; + if (![t appendRow:@[@3.14]]) /* double is default */ STFail(@"Cannot insert 'double'"); - if ([_table4 count] != 1) + if ([t count] != 1) STFail(@"1 row excepted"); +} - TightdbTable* _table5 = [[TightdbTable alloc] init]; - [_table5 addColumnWithType:tightdb_Float andName:@"first"]; - if (![_table5 appendRow:@[@3.14F]]) /* F == float */ +-(void)testAppendRowsFloatColumn +{ + TightdbTable* t = [[TightdbTable alloc] init]; + [t addColumnWithType:tightdb_Float andName:@"first"]; + if (![t appendRow:@[@3.14F]]) /* F == float */ STFail(@"Cannot insert 'float'"); - if ([_table5 count] != 1) + if ([t count] != 1) STFail(@"1 row excepted"); +} - TightdbTable* _table6 = [[TightdbTable alloc] init]; - [_table6 addColumnWithType:tightdb_Date andName:@"first"]; - if (![_table6 appendRow:@[@1000000000]]) /* 2001-09-09 01:46:40 */ +-(void)testAppendRowsDateColumn +{ + TightdbTable* t = [[TightdbTable alloc] init]; + [t addColumnWithType:tightdb_Date andName:@"first"]; + if (![t appendRow:@[@1000000000]]) /* 2001-09-09 01:46:40 */ STFail(@"Cannot insert 'time_t'"); - if ([_table6 count] != 1) + if ([t count] != 1) STFail(@"1 row excepted"); +} +-(void)testAppendRowsBinaryColumn +{ const char bin[4] = { 0, 1, 2, 3 }; TightdbBinary* bin2 = [[TightdbBinary alloc] initWithData:bin size:sizeof bin]; - TightdbTable* _table7 = [[TightdbTable alloc] init]; - [_table7 addColumnWithType:tightdb_Binary andName:@"first"]; - if (![_table7 appendRow:@[bin2]]) + TightdbTable* t = [[TightdbTable alloc] init]; + [t addColumnWithType:tightdb_Binary andName:@"first"]; + if (![t appendRow:@[bin2]]) STFail(@"Cannot insert 'binary'"); - if ([_table7 count] != 1) + if ([t count] != 1) STFail(@"1 row excepted"); +} + +-(void)testAppendRowsTooManyItems +{ +// SEGFAULT +// TightdbTable *t = [[TightdbTable alloc] init]; +// [t addColumnWithType:tightdb_Int andName:@"first"]; +// STAssertFalse(([t appendRow:@[@1, @1]]), @"Too many items for a row."); +} - TightdbTable* _table8 = [[TightdbTable alloc] init]; - [_table8 addColumnWithType:tightdb_Int andName:@"first"]; - TightdbDescriptor* _descr8 = [_table8 getDescriptor]; - TightdbDescriptor* _subdescr8 = [_descr8 addColumnTable:@"second"]; - [_subdescr8 addColumnWithType:tightdb_Int andName:@"TableCol_IntCol"]; - if (![_table8 appendRow:@[@1, @[]]]) +-(void)testAppendRowsTooFewItems +{ + TightdbTable *t = [[TightdbTable alloc] init]; + [t addColumnWithType:tightdb_Int andName:@"first"]; + STAssertFalse(([t appendRow:@[]]), @"Too few items for a row."); +} + +-(void)testAppendRowsIntSubtableColumns +{ + TightdbTable* t = [[TightdbTable alloc] init]; + [t addColumnWithType:tightdb_Int andName:@"first"]; + TightdbDescriptor* descr = [t getDescriptor]; + TightdbDescriptor* subdescr = [descr addColumnTable:@"second"]; + [subdescr addColumnWithType:tightdb_Int andName:@"TableCol_IntCol"]; + if (![t appendRow:@[@1, @[]]]) STFail(@"Cannot insert empty subtable"); - if ([_table8 count] != 1) + if ([t count] != 1) STFail(@"1 row excepted"); - if (![_table8 appendRow:@[@2, @[@[@3]]]]) + if (![t appendRow:@[@2, @[@[@3]]]]) STFail(@"Cannot insert subtable"); - if ([_table8 count] != 2) + if ([t count] != 2) STFail(@"2 rows excepted"); } From 1551a1997ade6e34dc21dbea5ff6bf058e4c200f Mon Sep 17 00:00:00 2001 From: oleks Date: Thu, 6 Mar 2014 13:28:04 +0100 Subject: [PATCH 2/5] Expected, not excepted. --- src/tightdb/objc/test/dynamic_table.m | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/tightdb/objc/test/dynamic_table.m b/src/tightdb/objc/test/dynamic_table.m index 3fa9911450..168d071030 100644 --- a/src/tightdb/objc/test/dynamic_table.m +++ b/src/tightdb/objc/test/dynamic_table.m @@ -73,15 +73,15 @@ -(void)testAppendRowsIntColumn if (![t appendRow:@[ @1 ]]) STFail(@"Impossible!"); if ([t count] != 1) - STFail(@"Excepted 1 row"); + STFail(@"Expected 1 row"); if (![t appendRow:@[ @2 ]]) STFail(@"Impossible!"); if ([t count] != 2) - STFail(@"Excepted 2 rows"); + STFail(@"Expected 2 rows"); if ([t getIntInColumn:0 atRow:0] != 1) - STFail(@"Value 1 excepted"); + STFail(@"Value 1 expected"); if ([t getIntInColumn:0 atRow:1] != 2) - STFail(@"Value 2 excepted"); + STFail(@"Value 2 expected"); if ([t appendRow:@[@"Hello"]]) STFail(@"Wrong type"); if ([t appendRow:@[@1, @"Hello"]]) @@ -98,9 +98,9 @@ -(void)testAppendRowsIntStringColumns if ([t count] != 1) STFail(@"1 row expected"); if ([t getIntInColumn:0 atRow:0] != 1) - STFail(@"Value 1 excepted"); + STFail(@"Value 1 expected"); if (![[t getStringInColumn:1 atRow:0] isEqualToString:@"Hello"]) - STFail(@"Value 'Hello' excepted"); + STFail(@"Value 'Hello' expected"); if ([t appendRow:@[@1, @2]]) STFail(@"appendRow 2"); } @@ -112,7 +112,7 @@ -(void)testAppendRowsDoubleColumn if (![t appendRow:@[@3.14]]) /* double is default */ STFail(@"Cannot insert 'double'"); if ([t count] != 1) - STFail(@"1 row excepted"); + STFail(@"1 row expected"); } -(void)testAppendRowsFloatColumn @@ -122,7 +122,7 @@ -(void)testAppendRowsFloatColumn if (![t appendRow:@[@3.14F]]) /* F == float */ STFail(@"Cannot insert 'float'"); if ([t count] != 1) - STFail(@"1 row excepted"); + STFail(@"1 row expected"); } -(void)testAppendRowsDateColumn @@ -132,7 +132,7 @@ -(void)testAppendRowsDateColumn if (![t appendRow:@[@1000000000]]) /* 2001-09-09 01:46:40 */ STFail(@"Cannot insert 'time_t'"); if ([t count] != 1) - STFail(@"1 row excepted"); + STFail(@"1 row expected"); } -(void)testAppendRowsBinaryColumn @@ -144,7 +144,7 @@ -(void)testAppendRowsBinaryColumn if (![t appendRow:@[bin2]]) STFail(@"Cannot insert 'binary'"); if ([t count] != 1) - STFail(@"1 row excepted"); + STFail(@"1 row expected"); } -(void)testAppendRowsTooManyItems @@ -172,11 +172,11 @@ -(void)testAppendRowsIntSubtableColumns if (![t appendRow:@[@1, @[]]]) STFail(@"Cannot insert empty subtable"); if ([t count] != 1) - STFail(@"1 row excepted"); + STFail(@"1 row expected"); if (![t appendRow:@[@2, @[@[@3]]]]) STFail(@"Cannot insert subtable"); if ([t count] != 2) - STFail(@"2 rows excepted"); + STFail(@"2 rows expected"); } - (void)testDataTypes_Dynamic From 3ab340343455d439c877f3d842cc1134f1ad1126 Mon Sep 17 00:00:00 2001 From: oleks Date: Thu, 6 Mar 2014 14:07:55 +0100 Subject: [PATCH 3/5] A couple more type-checking tests. --- src/tightdb/objc/test/dynamic_table.m | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/tightdb/objc/test/dynamic_table.m b/src/tightdb/objc/test/dynamic_table.m index 168d071030..7164c0008e 100644 --- a/src/tightdb/objc/test/dynamic_table.m +++ b/src/tightdb/objc/test/dynamic_table.m @@ -162,6 +162,26 @@ -(void)testAppendRowsTooFewItems STAssertFalse(([t appendRow:@[]]), @"Too few items for a row."); } +-(void)testAppendRowsWrongType +{ + TightdbTable *t = [[TightdbTable alloc] init]; + [t addColumnWithType:tightdb_Int andName:@"first"]; + STAssertFalse(([t appendRow:@[@true]]), @"Wrong type for column."); + STAssertFalse(([t appendRow:@[@""]]), @"Wrong type for column."); + STAssertFalse(([t appendRow:@[@3.5]]), @"Wrong type for column."); + STAssertFalse(([t appendRow:@[@3.5F]]), @"Wrong type for column."); + STAssertFalse(([t appendRow:@[@[]]]), @"Wrong type for column."); +} + +-(void)testAppendRowsBoolColumn +{ + TightdbTable *t = [[TightdbTable alloc] init]; + [t addColumnWithType:tightdb_Bool andName:@"first"]; + STAssertTrue(([t appendRow:@[@YES]]), @"Cannot append bool column."); + STAssertTrue(([t appendRow:@[@NO]]), @"Cannot append bool column."); + STAssertEquals(2, [t count], @"2 rows expected"); +} + -(void)testAppendRowsIntSubtableColumns { TightdbTable* t = [[TightdbTable alloc] init]; From 5a38ebe695057668a86ff688972d222d51901468 Mon Sep 17 00:00:00 2001 From: oleks Date: Thu, 6 Mar 2014 14:08:54 +0100 Subject: [PATCH 4/5] should not segfault anymore --- src/tightdb/objc/test/dynamic_table.m | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/tightdb/objc/test/dynamic_table.m b/src/tightdb/objc/test/dynamic_table.m index 7164c0008e..91f894e79a 100644 --- a/src/tightdb/objc/test/dynamic_table.m +++ b/src/tightdb/objc/test/dynamic_table.m @@ -149,10 +149,9 @@ -(void)testAppendRowsBinaryColumn -(void)testAppendRowsTooManyItems { -// SEGFAULT -// TightdbTable *t = [[TightdbTable alloc] init]; -// [t addColumnWithType:tightdb_Int andName:@"first"]; -// STAssertFalse(([t appendRow:@[@1, @1]]), @"Too many items for a row."); + TightdbTable *t = [[TightdbTable alloc] init]; + [t addColumnWithType:tightdb_Int andName:@"first"]; + STAssertFalse(([t appendRow:@[@1, @1]]), @"Too many items for a row."); } -(void)testAppendRowsTooFewItems From dfab7b3b1fa0fde7f20fabafb36496ce84a1b840 Mon Sep 17 00:00:00 2001 From: oleks Date: Thu, 6 Mar 2014 14:41:27 +0100 Subject: [PATCH 5/5] bugfixing --- src/tightdb/objc/test/dynamic_table.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tightdb/objc/test/dynamic_table.m b/src/tightdb/objc/test/dynamic_table.m index 91f894e79a..5032e567a8 100644 --- a/src/tightdb/objc/test/dynamic_table.m +++ b/src/tightdb/objc/test/dynamic_table.m @@ -165,7 +165,7 @@ -(void)testAppendRowsWrongType { TightdbTable *t = [[TightdbTable alloc] init]; [t addColumnWithType:tightdb_Int andName:@"first"]; - STAssertFalse(([t appendRow:@[@true]]), @"Wrong type for column."); + STAssertFalse(([t appendRow:@[@YES]]), @"Wrong type for column."); STAssertFalse(([t appendRow:@[@""]]), @"Wrong type for column."); STAssertFalse(([t appendRow:@[@3.5]]), @"Wrong type for column."); STAssertFalse(([t appendRow:@[@3.5F]]), @"Wrong type for column."); @@ -178,7 +178,7 @@ -(void)testAppendRowsBoolColumn [t addColumnWithType:tightdb_Bool andName:@"first"]; STAssertTrue(([t appendRow:@[@YES]]), @"Cannot append bool column."); STAssertTrue(([t appendRow:@[@NO]]), @"Cannot append bool column."); - STAssertEquals(2, [t count], @"2 rows expected"); + STAssertEquals((size_t)2, [t count], @"2 rows expected"); } -(void)testAppendRowsIntSubtableColumns