-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added sort on view and getColumnType on view #47
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
121d56a
added sort on view and getColumnType on view
764444f
changes.txt update
71116c6
added test case for date columns as well on tableview sort
2ba8ab4
surrounded m_view->sort with try catch
11a8637
added getColumnCount on view as well as check if col index is valid w…
35ffbe7
test case added for table view get column count
848ff30
changes.txt
b9d6502
removed unused @class import in query.h
51a23c1
Merge branch 'master' of github.com:Tightdb/tightdb_objc into view-sort
23940cd
resolved merge conflicts
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
/************************************************************************* | ||
* | ||
* TIGHTDB CONFIDENTIAL | ||
* __________________ | ||
* | ||
* [2011] - [2014] TightDB Inc | ||
* All Rights Reserved. | ||
* | ||
* NOTICE: All information contained herein is, and remains | ||
* the property of TightDB Incorporated and its suppliers, | ||
* if any. The intellectual and technical concepts contained | ||
* herein are proprietary to TightDB Incorporated | ||
* and its suppliers and may be covered by U.S. and Foreign Patents, | ||
* patents in process, and are protected by trade secret or copyright law. | ||
* Dissemination of this information or reproduction of this material | ||
* is strictly forbidden unless prior written permission is obtained | ||
* from TightDB Incorporated. | ||
* | ||
**************************************************************************/ | ||
|
||
#import <SenTestingKit/SenTestingKit.h> | ||
|
||
#import <tightdb/objc/tightdb.h> | ||
|
||
|
||
@interface table_view : SenTestCase | ||
|
||
@end | ||
|
||
@implementation table_view | ||
|
||
- (void)setUp | ||
{ | ||
[super setUp]; | ||
// Put setup code here; it will be run once, before the first test case. | ||
} | ||
|
||
- (void)tearDown | ||
{ | ||
// Put teardown code here; it will be run once, after the last test case. | ||
[super tearDown]; | ||
} | ||
|
||
- (void)testColumnTypesOnView | ||
{ | ||
TightdbTable *t = [[TightdbTable alloc] init]; | ||
|
||
NSUInteger boolCol = [t addColumnWithType:tightdb_Bool andName:@"boolCol"]; | ||
NSUInteger binaryCol = [t addColumnWithType:tightdb_Binary andName:@"binaryCol"]; | ||
NSUInteger dateCol = [t addColumnWithType:tightdb_Date andName:@"dateCol"]; | ||
NSUInteger doubleCol = [t addColumnWithType:tightdb_Double andName:@"doubleCol"]; | ||
NSUInteger floatCol = [t addColumnWithType:tightdb_Float andName:@"floatCol"]; | ||
NSUInteger intCol = [t addColumnWithType:tightdb_Int andName:@"intCol"]; | ||
NSUInteger mixedCol = [t addColumnWithType:tightdb_Mixed andName:@"MixedCol"]; | ||
NSUInteger stringCol = [t addColumnWithType:tightdb_String andName:@"stringCol"]; | ||
NSUInteger tableCol = [t addColumnWithType:tightdb_Table andName:@"tableCol"]; | ||
|
||
|
||
TightdbQuery *q = [t where]; | ||
TightdbView *v = [q findAll]; | ||
|
||
STAssertTrue([v getColumnType:boolCol] == tightdb_Bool, @"Column types matches"); | ||
STAssertTrue([v getColumnType:binaryCol] == tightdb_Binary, @"Column types matches"); | ||
STAssertTrue([v getColumnType:dateCol] == tightdb_Date, @"Column types matches"); | ||
STAssertTrue([v getColumnType:doubleCol] == tightdb_Double, @"Column types matches"); | ||
STAssertTrue([v getColumnType:floatCol] == tightdb_Float, @"Column types matches"); | ||
STAssertTrue([v getColumnType:intCol] == tightdb_Int, @"Column types matches"); | ||
STAssertTrue([v getColumnType:mixedCol] == tightdb_Mixed, @"Column types matches"); | ||
STAssertTrue([v getColumnType:stringCol] == tightdb_String, @"Column types matches"); | ||
STAssertTrue([v getColumnType:tableCol] == tightdb_Table, @"Column types matches"); | ||
} | ||
|
||
- (void)testSortOnViewIntColumn | ||
{ | ||
TightdbTable *t = [[TightdbTable alloc] init]; | ||
NSUInteger intCol = [t addColumnWithType:tightdb_Int andName:@"intCol"]; | ||
|
||
TightdbCursor *row = [t addEmptyRow]; | ||
[row setInt:2 inColumn:intCol]; | ||
|
||
row = [t addEmptyRow]; | ||
[row setInt:1 inColumn:intCol]; | ||
|
||
row = [t addEmptyRow]; | ||
[row setInt:0 inColumn:intCol]; | ||
|
||
TightdbQuery *q = [t where]; | ||
TightdbView *v = [q findAll]; | ||
|
||
// Not yet sorted | ||
STAssertTrue([v get:intCol ndx:0] == 2, @"matcing value after no sort"); | ||
STAssertTrue([v get:intCol ndx:1] == 1, @"matcing value after no sort"); | ||
STAssertTrue([v get:intCol ndx:2] == 0, @"matcing value after no sort"); | ||
|
||
// Sort same way without order specified. Ascending default | ||
[v sortColumnWithIndex:intCol]; | ||
STAssertTrue([v get:intCol ndx:0] == 0, @"matcing value after default sort"); | ||
STAssertTrue([v get:intCol ndx:1] == 1, @"matcing value after default sort"); | ||
STAssertTrue([v get:intCol ndx:2] == 2, @"matcing value after default sort"); | ||
|
||
// Sort same way | ||
[v sortColumnWithIndex:intCol inOrder:tightdb_ascending]; | ||
STAssertTrue([v get:intCol ndx:0] == 0, @"matcing value after ascending sort"); | ||
STAssertTrue([v get:intCol ndx:1] == 1, @"matcing value after ascending sort"); | ||
STAssertTrue([v get:intCol ndx:2] == 2, @"matcing value after ascending sort"); | ||
|
||
// Sort descending | ||
[v sortColumnWithIndex:intCol inOrder: tightdb_descending]; | ||
STAssertTrue([v get:intCol ndx:0] == 2, @"matcing value after descending sort"); | ||
STAssertTrue([v get:intCol ndx:1] == 1, @"matcing value after descending sort"); | ||
STAssertTrue([v get:intCol ndx:2] == 0, @"matcing value after descending sort"); | ||
} | ||
|
||
- (void)testSortOnViewBoolColumn | ||
{ | ||
TightdbTable *t = [[TightdbTable alloc] init]; | ||
NSUInteger boolCol = [t addColumnWithType:tightdb_Bool andName:@"boolCol"]; | ||
|
||
TightdbCursor *row = [t addEmptyRow]; | ||
[row setBool:YES inColumn:boolCol]; | ||
|
||
row = [t addEmptyRow]; | ||
[row setBool:YES inColumn:boolCol]; | ||
|
||
row = [t addEmptyRow]; | ||
[row setBool:NO inColumn:boolCol]; | ||
|
||
TightdbQuery *q = [t where]; | ||
TightdbView *v = [q findAll]; | ||
|
||
// Not yet sorted | ||
STAssertTrue([v getBool:boolCol ndx:0] == YES, @"matcing value after no sort"); | ||
STAssertTrue([v getBool:boolCol ndx:1] == YES, @"matcing value after no sort"); | ||
STAssertTrue([v getBool:boolCol ndx:2] == NO, @"matcing value after no sort"); | ||
|
||
// Sort same way without order specified. Ascending default | ||
[v sortColumnWithIndex:boolCol]; | ||
STAssertTrue([v getBool:boolCol ndx:0] == NO, @"matcing value after default sort"); | ||
STAssertTrue([v getBool:boolCol ndx:1] == YES, @"matcing value after default sort"); | ||
STAssertTrue([v getBool:boolCol ndx:2] == YES, @"matcing value after default sort"); | ||
|
||
// Sort same way | ||
[v sortColumnWithIndex:boolCol inOrder:tightdb_ascending]; | ||
STAssertTrue([v getBool:boolCol ndx:0] == NO, @"matcing value after ascending sort"); | ||
STAssertTrue([v getBool:boolCol ndx:1] == YES, @"matcing value after ascending sort"); | ||
STAssertTrue([v getBool:boolCol ndx:2] == YES, @"matcing value after ascending sort"); | ||
|
||
// Sort descending | ||
[v sortColumnWithIndex:boolCol inOrder: tightdb_descending]; | ||
STAssertTrue([v getBool:boolCol ndx:0] == YES, @"matcing value after descending sort"); | ||
STAssertTrue([v getBool:boolCol ndx:1] == YES, @"matcing value after descending sort"); | ||
STAssertTrue([v getBool:boolCol ndx:2] == NO, @"matcing value after descending sort"); | ||
} | ||
|
||
|
||
- (void)testSortOnViewDateColumn | ||
{ | ||
TightdbTable *t = [[TightdbTable alloc] init]; | ||
NSUInteger dateCol = [t addColumnWithType:tightdb_Date andName:@"dateCol"]; | ||
|
||
|
||
NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; | ||
[formatter setDateFormat:@"MM/dd/yyyy hh:mm a"]; | ||
|
||
NSDate *dateFirst = [formatter dateFromString:@"01/01/2014 10:10 PM"]; | ||
NSDate *dateMiddle = [formatter dateFromString:@"02/01/2014 10:10 PM"]; | ||
NSDate *dateLast = [formatter dateFromString:@"03/01/2014 10:10 PM"]; | ||
|
||
TightdbCursor *row = [t addEmptyRow]; | ||
[row setDate:[dateLast timeIntervalSince1970] inColumn:dateCol]; | ||
|
||
row = [t addEmptyRow]; | ||
[row setDate:[dateMiddle timeIntervalSince1970] inColumn:dateCol]; | ||
|
||
row = [t addEmptyRow]; | ||
[row setDate:[dateFirst timeIntervalSince1970] inColumn:dateCol]; | ||
|
||
TightdbQuery *q = [t where]; | ||
TightdbView *v = [q findAll]; | ||
|
||
// Not yet sorted | ||
STAssertTrue([v getDate:dateCol ndx:0] == [dateLast timeIntervalSince1970], @"matcing value after no sort"); | ||
STAssertTrue([v getDate:dateCol ndx:1] == [dateMiddle timeIntervalSince1970], @"matcing value after no sort"); | ||
STAssertTrue([v getDate:dateCol ndx:2] == [dateFirst timeIntervalSince1970], @"matcing value after no sort"); | ||
|
||
// Sort same way without order specified. Ascending default | ||
[v sortColumnWithIndex:dateCol]; | ||
STAssertTrue([v getDate:dateCol ndx:0] == [dateFirst timeIntervalSince1970], @"matcing value after default sort"); | ||
STAssertTrue([v getDate:dateCol ndx:1] == [dateMiddle timeIntervalSince1970], @"matcing value after default sort"); | ||
STAssertTrue([v getDate:dateCol ndx:2] == [dateLast timeIntervalSince1970], @"matcing value after default sort"); | ||
|
||
// Sort same way | ||
[v sortColumnWithIndex:dateCol inOrder:tightdb_ascending]; | ||
STAssertTrue([v getDate:dateCol ndx:0] == [dateFirst timeIntervalSince1970], @"matcing value after ascending sort"); | ||
STAssertTrue([v getDate:dateCol ndx:1] == [dateMiddle timeIntervalSince1970], @"matcing value after ascending sort"); | ||
STAssertTrue([v getDate:dateCol ndx:2] == [dateLast timeIntervalSince1970], @"matcing value after ascending sort"); | ||
|
||
// Sort descending | ||
[v sortColumnWithIndex:dateCol inOrder: tightdb_descending]; | ||
STAssertTrue([v getDate:dateCol ndx:0] == [dateLast timeIntervalSince1970], @"matcing value after descending sort"); | ||
STAssertTrue([v getDate:dateCol ndx:1] == [dateMiddle timeIntervalSince1970], @"matcing value after descending sort"); | ||
STAssertTrue([v getDate:dateCol ndx:2] == [dateFirst timeIntervalSince1970], @"matcing value after descending sort"); | ||
} | ||
|
||
|
||
- (void)testSortOnAllColumnTypes | ||
{ | ||
TightdbTable *t = [[TightdbTable alloc] init]; | ||
|
||
NSUInteger boolCol = [t addColumnWithType:tightdb_Bool andName:@"boolCol"]; | ||
NSUInteger binaryCol = [t addColumnWithType:tightdb_Binary andName:@"binaryCol"]; | ||
NSUInteger dateCol = [t addColumnWithType:tightdb_Date andName:@"dateCol"]; | ||
NSUInteger doubleCol = [t addColumnWithType:tightdb_Double andName:@"doubleCol"]; | ||
NSUInteger floatCol = [t addColumnWithType:tightdb_Float andName:@"floatCol"]; | ||
NSUInteger intCol = [t addColumnWithType:tightdb_Int andName:@"intCol"]; | ||
NSUInteger mixedCol = [t addColumnWithType:tightdb_Mixed andName:@"MixedCol"]; | ||
NSUInteger stringCol = [t addColumnWithType:tightdb_String andName:@"stringCol"]; | ||
NSUInteger tableCol = [t addColumnWithType:tightdb_Table andName:@"tableCol"]; | ||
|
||
TightdbQuery *q = [t where]; | ||
TightdbView *v = [q findAll]; | ||
|
||
[v sortColumnWithIndex:boolCol]; // bool is supported | ||
STAssertThrows([v sortColumnWithIndex:binaryCol], @"Not supported on binary column"); | ||
[v sortColumnWithIndex:dateCol]; // bool is supported | ||
STAssertThrows([v sortColumnWithIndex:doubleCol], @"Not supported on double column"); | ||
STAssertThrows([v sortColumnWithIndex:floatCol], @"Not supported on float column"); | ||
[v sortColumnWithIndex:intCol]; // int is supported | ||
STAssertThrows([v sortColumnWithIndex:mixedCol], @"Not supported on mixed column"); | ||
STAssertThrows([v sortColumnWithIndex:stringCol], @"Not supported on string column"); | ||
STAssertThrows([v sortColumnWithIndex:tableCol], @"Not supported on table column"); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, perhaps we should call these tightdb_sortAscending for better autocompletion and not to mix of when doing autocom for looking up column types