| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 5 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/mac/scoped_nsobject.h" | |
| 9 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 8 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "testing/gtest_mac.h" | 10 #include "testing/gtest_mac.h" |
| 12 | 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." |
| 14 #endif |
| 15 |
| 13 @interface CollectionViewModel (Testing) | 16 @interface CollectionViewModel (Testing) |
| 14 // Adds an item with the given type to the section with the given identifier. | 17 // Adds an item with the given type to the section with the given identifier. |
| 15 // It is possible to add multiple items with the same type to the same section. | 18 // It is possible to add multiple items with the same type to the same section. |
| 16 // Sharing types across sections is undefined behavior. | 19 // Sharing types across sections is undefined behavior. |
| 17 - (void)addItemWithType:(NSInteger)itemType | 20 - (void)addItemWithType:(NSInteger)itemType |
| 18 toSectionWithIdentifier:(NSInteger)sectionIdentifier; | 21 toSectionWithIdentifier:(NSInteger)sectionIdentifier; |
| 19 @end | 22 @end |
| 20 | 23 |
| 21 @implementation CollectionViewModel (Testing) | 24 @implementation CollectionViewModel (Testing) |
| 22 | 25 |
| 23 - (void)addItemWithType:(NSInteger)itemType | 26 - (void)addItemWithType:(NSInteger)itemType |
| 24 toSectionWithIdentifier:(NSInteger)sectionIdentifier { | 27 toSectionWithIdentifier:(NSInteger)sectionIdentifier { |
| 25 base::scoped_nsobject<CollectionViewItem> item( | 28 CollectionViewItem* item = [[CollectionViewItem alloc] initWithType:itemType]; |
| 26 [[CollectionViewItem alloc] initWithType:itemType]); | |
| 27 [self addItem:item toSectionWithIdentifier:sectionIdentifier]; | 29 [self addItem:item toSectionWithIdentifier:sectionIdentifier]; |
| 28 } | 30 } |
| 29 | 31 |
| 30 @end | 32 @end |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 34 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 36 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 35 SectionIdentifierCheese = kSectionIdentifierEnumZero, | 37 SectionIdentifierCheese = kSectionIdentifierEnumZero, |
| 36 SectionIdentifierWeasley, | 38 SectionIdentifierWeasley, |
| 37 }; | 39 }; |
| 38 | 40 |
| 39 typedef NS_ENUM(NSInteger, ItemType) { | 41 typedef NS_ENUM(NSInteger, ItemType) { |
| 40 ItemTypeCheeseHeader = kItemTypeEnumZero, | 42 ItemTypeCheeseHeader = kItemTypeEnumZero, |
| 41 ItemTypeCheeseCheddar, | 43 ItemTypeCheeseCheddar, |
| 42 ItemTypeCheeseGouda, | 44 ItemTypeCheeseGouda, |
| 43 ItemTypeCheesePepperJack, | 45 ItemTypeCheesePepperJack, |
| 44 ItemTypeWeasleyRon, | 46 ItemTypeWeasleyRon, |
| 45 ItemTypeWeasleyGinny, | 47 ItemTypeWeasleyGinny, |
| 46 ItemTypeWeasleyArthur, | 48 ItemTypeWeasleyArthur, |
| 47 ItemTypeWeasleyFooter, | 49 ItemTypeWeasleyFooter, |
| 48 }; | 50 }; |
| 49 | 51 |
| 50 void LogSink(const std::string& str) { | 52 void LogSink(const std::string& str) { |
| 51 // No-op. | 53 // No-op. |
| 52 } | 54 } |
| 53 | 55 |
| 54 TEST(CollectionViewModelTest, EmptyModel) { | 56 TEST(CollectionViewModelTest, EmptyModel) { |
| 55 base::scoped_nsobject<CollectionViewModel> model( | 57 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 56 [[CollectionViewModel alloc] init]); | |
| 57 | 58 |
| 58 // Check there are no items. | 59 // Check there are no items. |
| 59 EXPECT_EQ(NO, [model hasItemAtIndexPath:[NSIndexPath indexPathForItem:0 | 60 EXPECT_EQ(NO, [model hasItemAtIndexPath:[NSIndexPath indexPathForItem:0 |
| 60 inSection:0]]); | 61 inSection:0]]); |
| 61 | 62 |
| 62 // Check the collection view data sourcing methods. | 63 // Check the collection view data sourcing methods. |
| 63 EXPECT_EQ(0, [model numberOfSections]); | 64 EXPECT_EQ(0, [model numberOfSections]); |
| 64 } | 65 } |
| 65 | 66 |
| 66 TEST(CollectionViewModelTest, SingleSection) { | 67 TEST(CollectionViewModelTest, SingleSection) { |
| 67 base::scoped_nsobject<CollectionViewModel> model( | 68 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 68 [[CollectionViewModel alloc] init]); | |
| 69 | 69 |
| 70 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 70 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 71 [model addItemWithType:ItemTypeCheeseCheddar | 71 [model addItemWithType:ItemTypeCheeseCheddar |
| 72 toSectionWithIdentifier:SectionIdentifierCheese]; | 72 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 73 [model addItemWithType:ItemTypeCheeseGouda | 73 [model addItemWithType:ItemTypeCheeseGouda |
| 74 toSectionWithIdentifier:SectionIdentifierCheese]; | 74 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 75 [model addItemWithType:ItemTypeCheesePepperJack | 75 [model addItemWithType:ItemTypeCheesePepperJack |
| 76 toSectionWithIdentifier:SectionIdentifierCheese]; | 76 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 77 | 77 |
| 78 // Check there are some items but not more. | 78 // Check there are some items but not more. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 100 inSection:0]]); | 100 inSection:0]]); |
| 101 EXPECT_EQ(ItemTypeCheeseGouda, | 101 EXPECT_EQ(ItemTypeCheeseGouda, |
| 102 [model itemTypeForIndexPath:[NSIndexPath indexPathForItem:1 | 102 [model itemTypeForIndexPath:[NSIndexPath indexPathForItem:1 |
| 103 inSection:0]]); | 103 inSection:0]]); |
| 104 EXPECT_EQ(ItemTypeCheesePepperJack, | 104 EXPECT_EQ(ItemTypeCheesePepperJack, |
| 105 [model itemTypeForIndexPath:[NSIndexPath indexPathForItem:2 | 105 [model itemTypeForIndexPath:[NSIndexPath indexPathForItem:2 |
| 106 inSection:0]]); | 106 inSection:0]]); |
| 107 } | 107 } |
| 108 | 108 |
| 109 TEST(CollectionViewModelTest, SingleSectionWithMissingItems) { | 109 TEST(CollectionViewModelTest, SingleSectionWithMissingItems) { |
| 110 base::scoped_nsobject<CollectionViewModel> model( | 110 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 111 [[CollectionViewModel alloc] init]); | |
| 112 | 111 |
| 113 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 112 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 114 [model addItemWithType:ItemTypeCheeseCheddar | 113 [model addItemWithType:ItemTypeCheeseCheddar |
| 115 toSectionWithIdentifier:SectionIdentifierCheese]; | 114 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 116 // "Gouda" is intentionally omitted. | 115 // "Gouda" is intentionally omitted. |
| 117 [model addItemWithType:ItemTypeCheesePepperJack | 116 [model addItemWithType:ItemTypeCheesePepperJack |
| 118 toSectionWithIdentifier:SectionIdentifierCheese]; | 117 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 119 | 118 |
| 120 // Check the item type <-> item correspondance methods. | 119 // Check the item type <-> item correspondance methods. |
| 121 EXPECT_EQ(ItemTypeCheeseCheddar, | 120 EXPECT_EQ(ItemTypeCheeseCheddar, |
| 122 [model itemTypeForIndexPath:[NSIndexPath indexPathForItem:0 | 121 [model itemTypeForIndexPath:[NSIndexPath indexPathForItem:0 |
| 123 inSection:0]]); | 122 inSection:0]]); |
| 124 EXPECT_EQ(ItemTypeCheesePepperJack, | 123 EXPECT_EQ(ItemTypeCheesePepperJack, |
| 125 [model itemTypeForIndexPath:[NSIndexPath indexPathForItem:1 | 124 [model itemTypeForIndexPath:[NSIndexPath indexPathForItem:1 |
| 126 inSection:0]]); | 125 inSection:0]]); |
| 127 } | 126 } |
| 128 | 127 |
| 129 TEST(CollectionViewModelTest, MultipleSections) { | 128 TEST(CollectionViewModelTest, MultipleSections) { |
| 130 base::scoped_nsobject<CollectionViewModel> model( | 129 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 131 [[CollectionViewModel alloc] init]); | |
| 132 | 130 |
| 133 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 131 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 134 // "Cheddar" and "Gouda" are intentionally omitted. | 132 // "Cheddar" and "Gouda" are intentionally omitted. |
| 135 [model addItemWithType:ItemTypeCheesePepperJack | 133 [model addItemWithType:ItemTypeCheesePepperJack |
| 136 toSectionWithIdentifier:SectionIdentifierCheese]; | 134 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 137 | 135 |
| 138 [model addSectionWithIdentifier:SectionIdentifierWeasley]; | 136 [model addSectionWithIdentifier:SectionIdentifierWeasley]; |
| 139 // "Ron" is intentionally omitted. | 137 // "Ron" is intentionally omitted. |
| 140 [model addItemWithType:ItemTypeWeasleyGinny | 138 [model addItemWithType:ItemTypeWeasleyGinny |
| 141 toSectionWithIdentifier:SectionIdentifierWeasley]; | 139 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 158 inSection:0]]); | 156 inSection:0]]); |
| 159 EXPECT_EQ(ItemTypeWeasleyGinny, | 157 EXPECT_EQ(ItemTypeWeasleyGinny, |
| 160 [model itemTypeForIndexPath:[NSIndexPath indexPathForItem:0 | 158 [model itemTypeForIndexPath:[NSIndexPath indexPathForItem:0 |
| 161 inSection:1]]); | 159 inSection:1]]); |
| 162 EXPECT_EQ(ItemTypeWeasleyArthur, | 160 EXPECT_EQ(ItemTypeWeasleyArthur, |
| 163 [model itemTypeForIndexPath:[NSIndexPath indexPathForItem:1 | 161 [model itemTypeForIndexPath:[NSIndexPath indexPathForItem:1 |
| 164 inSection:1]]); | 162 inSection:1]]); |
| 165 } | 163 } |
| 166 | 164 |
| 167 TEST(CollectionViewModelTest, GetIndexPathFromModelCoordinates) { | 165 TEST(CollectionViewModelTest, GetIndexPathFromModelCoordinates) { |
| 168 base::scoped_nsobject<CollectionViewModel> model( | 166 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 169 [[CollectionViewModel alloc] init]); | |
| 170 | 167 |
| 171 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 168 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 172 [model addItemWithType:ItemTypeCheesePepperJack | 169 [model addItemWithType:ItemTypeCheesePepperJack |
| 173 toSectionWithIdentifier:SectionIdentifierCheese]; | 170 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 174 [model addSectionWithIdentifier:SectionIdentifierWeasley]; | 171 [model addSectionWithIdentifier:SectionIdentifierWeasley]; |
| 175 [model addItemWithType:ItemTypeWeasleyGinny | 172 [model addItemWithType:ItemTypeWeasleyGinny |
| 176 toSectionWithIdentifier:SectionIdentifierWeasley]; | 173 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 177 [model addItemWithType:ItemTypeWeasleyArthur | 174 [model addItemWithType:ItemTypeWeasleyArthur |
| 178 toSectionWithIdentifier:SectionIdentifierWeasley]; | 175 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 179 | 176 |
| 180 // Check the index path retrieval method for a single item. | 177 // Check the index path retrieval method for a single item. |
| 181 NSIndexPath* indexPath = | 178 NSIndexPath* indexPath = |
| 182 [model indexPathForItemType:ItemTypeWeasleyGinny | 179 [model indexPathForItemType:ItemTypeWeasleyGinny |
| 183 sectionIdentifier:SectionIdentifierWeasley]; | 180 sectionIdentifier:SectionIdentifierWeasley]; |
| 184 EXPECT_EQ(1, indexPath.section); | 181 EXPECT_EQ(1, indexPath.section); |
| 185 EXPECT_EQ(0, indexPath.item); | 182 EXPECT_EQ(0, indexPath.item); |
| 186 | 183 |
| 187 // Check the index path retrieval method for the first item. | 184 // Check the index path retrieval method for the first item. |
| 188 indexPath = [model indexPathForItemType:ItemTypeWeasleyGinny | 185 indexPath = [model indexPathForItemType:ItemTypeWeasleyGinny |
| 189 sectionIdentifier:SectionIdentifierWeasley | 186 sectionIdentifier:SectionIdentifierWeasley |
| 190 atIndex:0]; | 187 atIndex:0]; |
| 191 EXPECT_EQ(1, indexPath.section); | 188 EXPECT_EQ(1, indexPath.section); |
| 192 EXPECT_EQ(0, indexPath.item); | 189 EXPECT_EQ(0, indexPath.item); |
| 193 } | 190 } |
| 194 | 191 |
| 195 TEST(CollectionViewItemTest, RepeatedItems) { | 192 TEST(CollectionViewItemTest, RepeatedItems) { |
| 196 base::scoped_nsobject<CollectionViewModel> model( | 193 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 197 [[CollectionViewModel alloc] init]); | |
| 198 | 194 |
| 199 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 195 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 200 [model addItemWithType:ItemTypeCheesePepperJack | 196 [model addItemWithType:ItemTypeCheesePepperJack |
| 201 toSectionWithIdentifier:SectionIdentifierCheese]; | 197 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 202 [model addSectionWithIdentifier:SectionIdentifierWeasley]; | 198 [model addSectionWithIdentifier:SectionIdentifierWeasley]; |
| 203 [model addItemWithType:ItemTypeWeasleyGinny | 199 [model addItemWithType:ItemTypeWeasleyGinny |
| 204 toSectionWithIdentifier:SectionIdentifierWeasley]; | 200 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 205 [model addItemWithType:ItemTypeWeasleyArthur | 201 [model addItemWithType:ItemTypeWeasleyArthur |
| 206 toSectionWithIdentifier:SectionIdentifierWeasley]; | 202 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 207 [model addItemWithType:ItemTypeWeasleyArthur | 203 [model addItemWithType:ItemTypeWeasleyArthur |
| (...skipping 12 matching lines...) Expand all Loading... |
| 220 // Check the index path retrieval method for a repeated item. | 216 // Check the index path retrieval method for a repeated item. |
| 221 indexPath = [model indexPathForItemType:ItemTypeWeasleyArthur | 217 indexPath = [model indexPathForItemType:ItemTypeWeasleyArthur |
| 222 sectionIdentifier:SectionIdentifierWeasley | 218 sectionIdentifier:SectionIdentifierWeasley |
| 223 atIndex:1]; | 219 atIndex:1]; |
| 224 | 220 |
| 225 EXPECT_EQ(1, indexPath.section); | 221 EXPECT_EQ(1, indexPath.section); |
| 226 EXPECT_EQ(2, indexPath.item); | 222 EXPECT_EQ(2, indexPath.item); |
| 227 } | 223 } |
| 228 | 224 |
| 229 TEST(CollectionViewModelTest, RepeatedItemIndex) { | 225 TEST(CollectionViewModelTest, RepeatedItemIndex) { |
| 230 base::scoped_nsobject<CollectionViewModel> model( | 226 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 231 [[CollectionViewModel alloc] init]); | |
| 232 | 227 |
| 233 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 228 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 234 [model addItemWithType:ItemTypeCheesePepperJack | 229 [model addItemWithType:ItemTypeCheesePepperJack |
| 235 toSectionWithIdentifier:SectionIdentifierCheese]; | 230 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 236 [model addSectionWithIdentifier:SectionIdentifierWeasley]; | 231 [model addSectionWithIdentifier:SectionIdentifierWeasley]; |
| 237 [model addItemWithType:ItemTypeWeasleyGinny | 232 [model addItemWithType:ItemTypeWeasleyGinny |
| 238 toSectionWithIdentifier:SectionIdentifierWeasley]; | 233 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 239 [model addItemWithType:ItemTypeWeasleyArthur | 234 [model addItemWithType:ItemTypeWeasleyArthur |
| 240 toSectionWithIdentifier:SectionIdentifierWeasley]; | 235 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 241 [model addItemWithType:ItemTypeWeasleyArthur | 236 [model addItemWithType:ItemTypeWeasleyArthur |
| (...skipping 14 matching lines...) Expand all Loading... |
| 256 inSection:1]]); | 251 inSection:1]]); |
| 257 EXPECT_EQ( | 252 EXPECT_EQ( |
| 258 2U, [model indexInItemTypeForIndexPath:[NSIndexPath indexPathForItem:3 | 253 2U, [model indexInItemTypeForIndexPath:[NSIndexPath indexPathForItem:3 |
| 259 inSection:1]]); | 254 inSection:1]]); |
| 260 EXPECT_EQ( | 255 EXPECT_EQ( |
| 261 3U, [model indexInItemTypeForIndexPath:[NSIndexPath indexPathForItem:5 | 256 3U, [model indexInItemTypeForIndexPath:[NSIndexPath indexPathForItem:5 |
| 262 inSection:1]]); | 257 inSection:1]]); |
| 263 } | 258 } |
| 264 | 259 |
| 265 TEST(CollectionViewModelTest, RetrieveAddedItem) { | 260 TEST(CollectionViewModelTest, RetrieveAddedItem) { |
| 266 base::scoped_nsobject<CollectionViewModel> model( | 261 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 267 [[CollectionViewModel alloc] init]); | |
| 268 | 262 |
| 269 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 263 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 270 base::scoped_nsobject<CollectionViewItem> someItem( | 264 CollectionViewItem* someItem = |
| 271 [[CollectionViewItem alloc] initWithType:ItemTypeCheeseGouda]); | 265 [[CollectionViewItem alloc] initWithType:ItemTypeCheeseGouda]; |
| 272 [model addItem:someItem toSectionWithIdentifier:SectionIdentifierCheese]; | 266 [model addItem:someItem toSectionWithIdentifier:SectionIdentifierCheese]; |
| 273 | 267 |
| 274 // Check that the item is the same in the model. | 268 // Check that the item is the same in the model. |
| 275 EXPECT_EQ(someItem, [model itemAtIndexPath:[NSIndexPath indexPathForItem:0 | 269 EXPECT_EQ(someItem, [model itemAtIndexPath:[NSIndexPath indexPathForItem:0 |
| 276 inSection:0]]); | 270 inSection:0]]); |
| 277 } | 271 } |
| 278 | 272 |
| 279 TEST(CollectionViewModelTest, RetrieveItemsInSection) { | 273 TEST(CollectionViewModelTest, RetrieveItemsInSection) { |
| 280 base::scoped_nsobject<CollectionViewModel> model( | 274 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 281 [[CollectionViewModel alloc] init]); | |
| 282 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 275 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 283 base::scoped_nsobject<CollectionViewItem> cheddar( | 276 CollectionViewItem* cheddar = |
| 284 [[CollectionViewItem alloc] initWithType:ItemTypeCheeseCheddar]); | 277 [[CollectionViewItem alloc] initWithType:ItemTypeCheeseCheddar]; |
| 285 [model addItem:cheddar toSectionWithIdentifier:SectionIdentifierCheese]; | 278 [model addItem:cheddar toSectionWithIdentifier:SectionIdentifierCheese]; |
| 286 base::scoped_nsobject<CollectionViewItem> pepperJack( | 279 CollectionViewItem* pepperJack = |
| 287 [[CollectionViewItem alloc] initWithType:ItemTypeCheesePepperJack]); | 280 [[CollectionViewItem alloc] initWithType:ItemTypeCheesePepperJack]; |
| 288 [model addItem:pepperJack toSectionWithIdentifier:SectionIdentifierCheese]; | 281 [model addItem:pepperJack toSectionWithIdentifier:SectionIdentifierCheese]; |
| 289 base::scoped_nsobject<CollectionViewItem> gouda( | 282 CollectionViewItem* gouda = |
| 290 [[CollectionViewItem alloc] initWithType:ItemTypeCheeseGouda]); | 283 [[CollectionViewItem alloc] initWithType:ItemTypeCheeseGouda]; |
| 291 [model addItem:gouda toSectionWithIdentifier:SectionIdentifierCheese]; | 284 [model addItem:gouda toSectionWithIdentifier:SectionIdentifierCheese]; |
| 292 | 285 |
| 293 NSArray* cheeseItems = | 286 NSArray* cheeseItems = |
| 294 [model itemsInSectionWithIdentifier:SectionIdentifierCheese]; | 287 [model itemsInSectionWithIdentifier:SectionIdentifierCheese]; |
| 295 EXPECT_EQ(3U, [cheeseItems count]); | 288 EXPECT_EQ(3U, [cheeseItems count]); |
| 296 EXPECT_NSEQ(cheddar, cheeseItems[0]); | 289 EXPECT_NSEQ(cheddar, cheeseItems[0]); |
| 297 EXPECT_NSEQ(pepperJack, cheeseItems[1]); | 290 EXPECT_NSEQ(pepperJack, cheeseItems[1]); |
| 298 EXPECT_NSEQ(gouda, cheeseItems[2]); | 291 EXPECT_NSEQ(gouda, cheeseItems[2]); |
| 299 } | 292 } |
| 300 | 293 |
| 301 TEST(CollectionViewModelTest, InvalidIndexPath) { | 294 TEST(CollectionViewModelTest, InvalidIndexPath) { |
| 302 base::scoped_nsobject<CollectionViewModel> model( | 295 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 303 [[CollectionViewModel alloc] init]); | |
| 304 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 296 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 305 | 297 |
| 306 logging::SetLogAssertHandler(&LogSink); | 298 logging::SetLogAssertHandler(&LogSink); |
| 307 bool out_of_bounds_exception_thrown = false; | 299 bool out_of_bounds_exception_thrown = false; |
| 308 @try { | 300 @try { |
| 309 [model indexInItemTypeForIndexPath:[NSIndexPath indexPathForItem:0 | 301 [model indexInItemTypeForIndexPath:[NSIndexPath indexPathForItem:0 |
| 310 inSection:0]]; | 302 inSection:0]]; |
| 311 } @catch (NSException* exception) { | 303 } @catch (NSException* exception) { |
| 312 if ([[exception name] isEqualToString:NSRangeException]) { | 304 if ([[exception name] isEqualToString:NSRangeException]) { |
| 313 out_of_bounds_exception_thrown = true; | 305 out_of_bounds_exception_thrown = true; |
| 314 } | 306 } |
| 315 } | 307 } |
| 316 EXPECT_TRUE(out_of_bounds_exception_thrown); | 308 EXPECT_TRUE(out_of_bounds_exception_thrown); |
| 317 logging::SetLogAssertHandler(nullptr); | 309 logging::SetLogAssertHandler(nullptr); |
| 318 } | 310 } |
| 319 | 311 |
| 320 TEST(CollectionViewModelTest, RemoveItems) { | 312 TEST(CollectionViewModelTest, RemoveItems) { |
| 321 base::scoped_nsobject<CollectionViewModel> model( | 313 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 322 [[CollectionViewModel alloc] init]); | |
| 323 | 314 |
| 324 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 315 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 325 [model addItemWithType:ItemTypeCheesePepperJack | 316 [model addItemWithType:ItemTypeCheesePepperJack |
| 326 toSectionWithIdentifier:SectionIdentifierCheese]; | 317 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 327 [model addItemWithType:ItemTypeCheeseGouda | 318 [model addItemWithType:ItemTypeCheeseGouda |
| 328 toSectionWithIdentifier:SectionIdentifierCheese]; | 319 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 329 | 320 |
| 330 [model addSectionWithIdentifier:SectionIdentifierWeasley]; | 321 [model addSectionWithIdentifier:SectionIdentifierWeasley]; |
| 331 [model addItemWithType:ItemTypeWeasleyGinny | 322 [model addItemWithType:ItemTypeWeasleyGinny |
| 332 toSectionWithIdentifier:SectionIdentifierWeasley]; | 323 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 EXPECT_EQ(1, indexPath.item); | 355 EXPECT_EQ(1, indexPath.item); |
| 365 | 356 |
| 366 // Check the index path retrieval method for a single item. | 357 // Check the index path retrieval method for a single item. |
| 367 indexPath = [model indexPathForItemType:ItemTypeWeasleyRon | 358 indexPath = [model indexPathForItemType:ItemTypeWeasleyRon |
| 368 sectionIdentifier:SectionIdentifierWeasley]; | 359 sectionIdentifier:SectionIdentifierWeasley]; |
| 369 EXPECT_EQ(1, indexPath.section); | 360 EXPECT_EQ(1, indexPath.section); |
| 370 EXPECT_EQ(2, indexPath.item); | 361 EXPECT_EQ(2, indexPath.item); |
| 371 } | 362 } |
| 372 | 363 |
| 373 TEST(CollectionViewModelTest, RemoveSections) { | 364 TEST(CollectionViewModelTest, RemoveSections) { |
| 374 base::scoped_nsobject<CollectionViewModel> model( | 365 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 375 [[CollectionViewModel alloc] init]); | |
| 376 | 366 |
| 377 // Empty section. | 367 // Empty section. |
| 378 [model addSectionWithIdentifier:SectionIdentifierWeasley]; | 368 [model addSectionWithIdentifier:SectionIdentifierWeasley]; |
| 379 | 369 |
| 380 // Section with items. | 370 // Section with items. |
| 381 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 371 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 382 [model addItemWithType:ItemTypeCheesePepperJack | 372 [model addItemWithType:ItemTypeCheesePepperJack |
| 383 toSectionWithIdentifier:SectionIdentifierCheese]; | 373 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 384 [model addItemWithType:ItemTypeCheeseGouda | 374 [model addItemWithType:ItemTypeCheeseGouda |
| 385 toSectionWithIdentifier:SectionIdentifierCheese]; | 375 toSectionWithIdentifier:SectionIdentifierCheese]; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 397 EXPECT_EQ(2, [model numberOfItemsInSection:0]); | 387 EXPECT_EQ(2, [model numberOfItemsInSection:0]); |
| 398 | 388 |
| 399 // Remove a section with items. | 389 // Remove a section with items. |
| 400 [model removeSectionWithIdentifier:SectionIdentifierCheese]; | 390 [model removeSectionWithIdentifier:SectionIdentifierCheese]; |
| 401 | 391 |
| 402 // Check that the section and its items were removed. | 392 // Check that the section and its items were removed. |
| 403 EXPECT_EQ(0, [model numberOfSections]); | 393 EXPECT_EQ(0, [model numberOfSections]); |
| 404 } | 394 } |
| 405 | 395 |
| 406 TEST(CollectionViewModelTest, QueryItemsFromModelCoordinates) { | 396 TEST(CollectionViewModelTest, QueryItemsFromModelCoordinates) { |
| 407 base::scoped_nsobject<CollectionViewModel> model( | 397 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 408 [[CollectionViewModel alloc] init]); | |
| 409 | 398 |
| 410 EXPECT_FALSE([model hasSectionForSectionIdentifier:SectionIdentifierWeasley]); | 399 EXPECT_FALSE([model hasSectionForSectionIdentifier:SectionIdentifierWeasley]); |
| 411 EXPECT_FALSE([model hasItemForItemType:ItemTypeCheeseCheddar | 400 EXPECT_FALSE([model hasItemForItemType:ItemTypeCheeseCheddar |
| 412 sectionIdentifier:SectionIdentifierCheese]); | 401 sectionIdentifier:SectionIdentifierCheese]); |
| 413 EXPECT_FALSE([model hasItemForItemType:ItemTypeCheeseGouda | 402 EXPECT_FALSE([model hasItemForItemType:ItemTypeCheeseGouda |
| 414 sectionIdentifier:SectionIdentifierCheese | 403 sectionIdentifier:SectionIdentifierCheese |
| 415 atIndex:1]); | 404 atIndex:1]); |
| 416 | 405 |
| 417 // Section with items. | 406 // Section with items. |
| 418 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 407 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 419 [model addItemWithType:ItemTypeCheesePepperJack | 408 [model addItemWithType:ItemTypeCheesePepperJack |
| 420 toSectionWithIdentifier:SectionIdentifierCheese]; | 409 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 421 [model addItemWithType:ItemTypeCheeseGouda | 410 [model addItemWithType:ItemTypeCheeseGouda |
| 422 toSectionWithIdentifier:SectionIdentifierCheese]; | 411 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 423 [model addItemWithType:ItemTypeCheeseGouda | 412 [model addItemWithType:ItemTypeCheeseGouda |
| 424 toSectionWithIdentifier:SectionIdentifierCheese]; | 413 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 425 | 414 |
| 426 EXPECT_TRUE([model hasSectionForSectionIdentifier:SectionIdentifierCheese]); | 415 EXPECT_TRUE([model hasSectionForSectionIdentifier:SectionIdentifierCheese]); |
| 427 EXPECT_FALSE([model hasItemForItemType:ItemTypeCheeseCheddar | 416 EXPECT_FALSE([model hasItemForItemType:ItemTypeCheeseCheddar |
| 428 sectionIdentifier:SectionIdentifierCheese]); | 417 sectionIdentifier:SectionIdentifierCheese]); |
| 429 EXPECT_TRUE([model hasItemForItemType:ItemTypeCheesePepperJack | 418 EXPECT_TRUE([model hasItemForItemType:ItemTypeCheesePepperJack |
| 430 sectionIdentifier:SectionIdentifierCheese]); | 419 sectionIdentifier:SectionIdentifierCheese]); |
| 431 EXPECT_TRUE([model hasItemForItemType:ItemTypeCheeseGouda | 420 EXPECT_TRUE([model hasItemForItemType:ItemTypeCheeseGouda |
| 432 sectionIdentifier:SectionIdentifierCheese | 421 sectionIdentifier:SectionIdentifierCheese |
| 433 atIndex:1]); | 422 atIndex:1]); |
| 434 } | 423 } |
| 435 | 424 |
| 436 // Tests that inserted sections are added at the correct index. | 425 // Tests that inserted sections are added at the correct index. |
| 437 TEST(CollectionViewModelTest, InsertSections) { | 426 TEST(CollectionViewModelTest, InsertSections) { |
| 438 base::scoped_nsobject<CollectionViewModel> model( | 427 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 439 [[CollectionViewModel alloc] init]); | |
| 440 | 428 |
| 441 [model addSectionWithIdentifier:SectionIdentifierWeasley]; | 429 [model addSectionWithIdentifier:SectionIdentifierWeasley]; |
| 442 EXPECT_EQ(1, [model numberOfSections]); | 430 EXPECT_EQ(1, [model numberOfSections]); |
| 443 EXPECT_EQ(0, [model sectionForSectionIdentifier:SectionIdentifierWeasley]); | 431 EXPECT_EQ(0, [model sectionForSectionIdentifier:SectionIdentifierWeasley]); |
| 444 | 432 |
| 445 [model insertSectionWithIdentifier:SectionIdentifierCheese atIndex:0]; | 433 [model insertSectionWithIdentifier:SectionIdentifierCheese atIndex:0]; |
| 446 EXPECT_EQ(2, [model numberOfSections]); | 434 EXPECT_EQ(2, [model numberOfSections]); |
| 447 EXPECT_EQ(1, [model sectionForSectionIdentifier:SectionIdentifierWeasley]); | 435 EXPECT_EQ(1, [model sectionForSectionIdentifier:SectionIdentifierWeasley]); |
| 448 EXPECT_EQ(0, [model sectionForSectionIdentifier:SectionIdentifierCheese]); | 436 EXPECT_EQ(0, [model sectionForSectionIdentifier:SectionIdentifierCheese]); |
| 449 | 437 |
| 450 [model removeSectionWithIdentifier:SectionIdentifierCheese]; | 438 [model removeSectionWithIdentifier:SectionIdentifierCheese]; |
| 451 [model insertSectionWithIdentifier:SectionIdentifierCheese atIndex:1]; | 439 [model insertSectionWithIdentifier:SectionIdentifierCheese atIndex:1]; |
| 452 EXPECT_EQ(2, [model numberOfSections]); | 440 EXPECT_EQ(2, [model numberOfSections]); |
| 453 EXPECT_EQ(0, [model sectionForSectionIdentifier:SectionIdentifierWeasley]); | 441 EXPECT_EQ(0, [model sectionForSectionIdentifier:SectionIdentifierWeasley]); |
| 454 EXPECT_EQ(1, [model sectionForSectionIdentifier:SectionIdentifierCheese]); | 442 EXPECT_EQ(1, [model sectionForSectionIdentifier:SectionIdentifierCheese]); |
| 455 } | 443 } |
| 456 | 444 |
| 457 // Tests that inserted items are added at the correct index. | 445 // Tests that inserted items are added at the correct index. |
| 458 TEST(CollectionViewModelTest, InsertItemAtIndex) { | 446 TEST(CollectionViewModelTest, InsertItemAtIndex) { |
| 459 base::scoped_nsobject<CollectionViewModel> model( | 447 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 460 [[CollectionViewModel alloc] init]); | |
| 461 | 448 |
| 462 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 449 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 463 [model addItemWithType:ItemTypeCheesePepperJack | 450 [model addItemWithType:ItemTypeCheesePepperJack |
| 464 toSectionWithIdentifier:SectionIdentifierCheese]; | 451 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 465 [model addItemWithType:ItemTypeCheeseGouda | 452 [model addItemWithType:ItemTypeCheeseGouda |
| 466 toSectionWithIdentifier:SectionIdentifierCheese]; | 453 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 467 base::scoped_nsobject<CollectionViewItem> cheddarItem( | 454 CollectionViewItem* cheddarItem = |
| 468 [[CollectionViewItem alloc] initWithType:ItemTypeCheeseCheddar]); | 455 [[CollectionViewItem alloc] initWithType:ItemTypeCheeseCheddar]; |
| 469 [model insertItem:cheddarItem | 456 [model insertItem:cheddarItem |
| 470 inSectionWithIdentifier:SectionIdentifierCheese | 457 inSectionWithIdentifier:SectionIdentifierCheese |
| 471 atIndex:1]; | 458 atIndex:1]; |
| 472 | 459 |
| 473 EXPECT_EQ(1, [model numberOfSections]); | 460 EXPECT_EQ(1, [model numberOfSections]); |
| 474 | 461 |
| 475 NSIndexPath* pepperJackIndexPath = | 462 NSIndexPath* pepperJackIndexPath = |
| 476 [model indexPathForItemType:ItemTypeCheesePepperJack | 463 [model indexPathForItemType:ItemTypeCheesePepperJack |
| 477 sectionIdentifier:SectionIdentifierCheese]; | 464 sectionIdentifier:SectionIdentifierCheese]; |
| 478 EXPECT_EQ(0, pepperJackIndexPath.section); | 465 EXPECT_EQ(0, pepperJackIndexPath.section); |
| 479 EXPECT_EQ(0, pepperJackIndexPath.item); | 466 EXPECT_EQ(0, pepperJackIndexPath.item); |
| 480 | 467 |
| 481 NSIndexPath* cheddarIndexPath = | 468 NSIndexPath* cheddarIndexPath = |
| 482 [model indexPathForItemType:ItemTypeCheeseCheddar | 469 [model indexPathForItemType:ItemTypeCheeseCheddar |
| 483 sectionIdentifier:SectionIdentifierCheese]; | 470 sectionIdentifier:SectionIdentifierCheese]; |
| 484 EXPECT_EQ(0, cheddarIndexPath.section); | 471 EXPECT_EQ(0, cheddarIndexPath.section); |
| 485 EXPECT_EQ(1, cheddarIndexPath.item); | 472 EXPECT_EQ(1, cheddarIndexPath.item); |
| 486 | 473 |
| 487 NSIndexPath* goudaIndexPath = | 474 NSIndexPath* goudaIndexPath = |
| 488 [model indexPathForItemType:ItemTypeCheeseGouda | 475 [model indexPathForItemType:ItemTypeCheeseGouda |
| 489 sectionIdentifier:SectionIdentifierCheese]; | 476 sectionIdentifier:SectionIdentifierCheese]; |
| 490 EXPECT_EQ(0, goudaIndexPath.section); | 477 EXPECT_EQ(0, goudaIndexPath.section); |
| 491 EXPECT_EQ(2, goudaIndexPath.item); | 478 EXPECT_EQ(2, goudaIndexPath.item); |
| 492 } | 479 } |
| 493 | 480 |
| 494 TEST(CollectionViewModelTest, IndexPathsForItems) { | 481 TEST(CollectionViewModelTest, IndexPathsForItems) { |
| 495 base::scoped_nsobject<CollectionViewModel> model( | 482 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 496 [[CollectionViewModel alloc] init]); | |
| 497 | 483 |
| 498 [model addSectionWithIdentifier:SectionIdentifierWeasley]; | 484 [model addSectionWithIdentifier:SectionIdentifierWeasley]; |
| 499 [model addItemWithType:ItemTypeWeasleyGinny | 485 [model addItemWithType:ItemTypeWeasleyGinny |
| 500 toSectionWithIdentifier:SectionIdentifierWeasley]; | 486 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 501 // Added at index 1. | 487 // Added at index 1. |
| 502 base::scoped_nsobject<CollectionViewItem> item1( | 488 CollectionViewItem* item1 = |
| 503 [[CollectionViewItem alloc] initWithType:ItemTypeWeasleyRon]); | 489 [[CollectionViewItem alloc] initWithType:ItemTypeWeasleyRon]; |
| 504 [model addItem:item1 toSectionWithIdentifier:SectionIdentifierWeasley]; | 490 [model addItem:item1 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 505 [model addItemWithType:ItemTypeWeasleyGinny | 491 [model addItemWithType:ItemTypeWeasleyGinny |
| 506 toSectionWithIdentifier:SectionIdentifierWeasley]; | 492 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 507 [model addItemWithType:ItemTypeWeasleyArthur | 493 [model addItemWithType:ItemTypeWeasleyArthur |
| 508 toSectionWithIdentifier:SectionIdentifierWeasley]; | 494 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 509 // Repeated item added at index 4. | 495 // Repeated item added at index 4. |
| 510 base::scoped_nsobject<CollectionViewItem> item4( | 496 CollectionViewItem* item4 = |
| 511 [[CollectionViewItem alloc] initWithType:ItemTypeWeasleyArthur]); | 497 [[CollectionViewItem alloc] initWithType:ItemTypeWeasleyArthur]; |
| 512 [model addItem:item4 toSectionWithIdentifier:SectionIdentifierWeasley]; | 498 [model addItem:item4 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 513 [model addItemWithType:ItemTypeWeasleyArthur | 499 [model addItemWithType:ItemTypeWeasleyArthur |
| 514 toSectionWithIdentifier:SectionIdentifierWeasley]; | 500 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 515 [model addItemWithType:ItemTypeWeasleyArthur | 501 [model addItemWithType:ItemTypeWeasleyArthur |
| 516 toSectionWithIdentifier:SectionIdentifierWeasley]; | 502 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 517 | 503 |
| 518 NSIndexPath* indexPath1 = [model indexPathForItem:item1 | 504 NSIndexPath* indexPath1 = [model indexPathForItem:item1 |
| 519 inSectionWithIdentifier:SectionIdentifierWeasley]; | 505 inSectionWithIdentifier:SectionIdentifierWeasley]; |
| 520 EXPECT_EQ(0, indexPath1.section); | 506 EXPECT_EQ(0, indexPath1.section); |
| 521 EXPECT_EQ(1, indexPath1.item); | 507 EXPECT_EQ(1, indexPath1.item); |
| 522 | 508 |
| 523 NSIndexPath* indexPath4 = [model indexPathForItem:item4 | 509 NSIndexPath* indexPath4 = [model indexPathForItem:item4 |
| 524 inSectionWithIdentifier:SectionIdentifierWeasley]; | 510 inSectionWithIdentifier:SectionIdentifierWeasley]; |
| 525 EXPECT_EQ(0, indexPath4.section); | 511 EXPECT_EQ(0, indexPath4.section); |
| 526 EXPECT_EQ(4, indexPath4.item); | 512 EXPECT_EQ(4, indexPath4.item); |
| 527 } | 513 } |
| 528 | 514 |
| 529 TEST(CollectionViewModelTest, Headers) { | 515 TEST(CollectionViewModelTest, Headers) { |
| 530 base::scoped_nsobject<CollectionViewModel> model( | 516 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 531 [[CollectionViewModel alloc] init]); | |
| 532 | 517 |
| 533 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 518 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 534 base::scoped_nsobject<CollectionViewItem> cheeseHeader( | 519 CollectionViewItem* cheeseHeader = |
| 535 [[CollectionViewItem alloc] initWithType:ItemTypeCheeseHeader]); | 520 [[CollectionViewItem alloc] initWithType:ItemTypeCheeseHeader]; |
| 536 [model setHeader:cheeseHeader | 521 [model setHeader:cheeseHeader |
| 537 forSectionWithIdentifier:SectionIdentifierCheese]; | 522 forSectionWithIdentifier:SectionIdentifierCheese]; |
| 538 [model addItemWithType:ItemTypeCheeseGouda | 523 [model addItemWithType:ItemTypeCheeseGouda |
| 539 toSectionWithIdentifier:SectionIdentifierCheese]; | 524 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 540 [model addItemWithType:ItemTypeCheeseCheddar | 525 [model addItemWithType:ItemTypeCheeseCheddar |
| 541 toSectionWithIdentifier:SectionIdentifierCheese]; | 526 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 542 [model addSectionWithIdentifier:SectionIdentifierWeasley]; | 527 [model addSectionWithIdentifier:SectionIdentifierWeasley]; |
| 543 [model addItemWithType:ItemTypeWeasleyRon | 528 [model addItemWithType:ItemTypeWeasleyRon |
| 544 toSectionWithIdentifier:SectionIdentifierWeasley]; | 529 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 545 [model addItemWithType:ItemTypeWeasleyGinny | 530 [model addItemWithType:ItemTypeWeasleyGinny |
| 546 toSectionWithIdentifier:SectionIdentifierWeasley]; | 531 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 547 | 532 |
| 548 NSInteger cheeseSection = | 533 NSInteger cheeseSection = |
| 549 [model sectionForSectionIdentifier:SectionIdentifierCheese]; | 534 [model sectionForSectionIdentifier:SectionIdentifierCheese]; |
| 550 NSInteger weasleySection = | 535 NSInteger weasleySection = |
| 551 [model sectionForSectionIdentifier:SectionIdentifierWeasley]; | 536 [model sectionForSectionIdentifier:SectionIdentifierWeasley]; |
| 552 | 537 |
| 553 EXPECT_EQ(cheeseHeader.get(), | 538 EXPECT_EQ(cheeseHeader, |
| 554 [model headerForSectionWithIdentifier:SectionIdentifierCheese]); | 539 [model headerForSectionWithIdentifier:SectionIdentifierCheese]); |
| 555 EXPECT_EQ(cheeseHeader.get(), [model headerForSection:cheeseSection]); | 540 EXPECT_EQ(cheeseHeader, [model headerForSection:cheeseSection]); |
| 556 | 541 |
| 557 EXPECT_FALSE([model headerForSectionWithIdentifier:SectionIdentifierWeasley]); | 542 EXPECT_FALSE([model headerForSectionWithIdentifier:SectionIdentifierWeasley]); |
| 558 EXPECT_FALSE([model headerForSection:weasleySection]); | 543 EXPECT_FALSE([model headerForSection:weasleySection]); |
| 559 } | 544 } |
| 560 | 545 |
| 561 TEST(CollectionViewModelTest, Footers) { | 546 TEST(CollectionViewModelTest, Footers) { |
| 562 base::scoped_nsobject<CollectionViewModel> model( | 547 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 563 [[CollectionViewModel alloc] init]); | |
| 564 | 548 |
| 565 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 549 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
| 566 [model addItemWithType:ItemTypeCheeseGouda | 550 [model addItemWithType:ItemTypeCheeseGouda |
| 567 toSectionWithIdentifier:SectionIdentifierCheese]; | 551 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 568 [model addItemWithType:ItemTypeCheeseCheddar | 552 [model addItemWithType:ItemTypeCheeseCheddar |
| 569 toSectionWithIdentifier:SectionIdentifierCheese]; | 553 toSectionWithIdentifier:SectionIdentifierCheese]; |
| 570 [model addSectionWithIdentifier:SectionIdentifierWeasley]; | 554 [model addSectionWithIdentifier:SectionIdentifierWeasley]; |
| 571 [model addItemWithType:ItemTypeWeasleyRon | 555 [model addItemWithType:ItemTypeWeasleyRon |
| 572 toSectionWithIdentifier:SectionIdentifierWeasley]; | 556 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 573 [model addItemWithType:ItemTypeWeasleyGinny | 557 [model addItemWithType:ItemTypeWeasleyGinny |
| 574 toSectionWithIdentifier:SectionIdentifierWeasley]; | 558 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 575 base::scoped_nsobject<CollectionViewItem> weasleyFooter( | 559 CollectionViewItem* weasleyFooter = |
| 576 [[CollectionViewItem alloc] initWithType:ItemTypeWeasleyFooter]); | 560 [[CollectionViewItem alloc] initWithType:ItemTypeWeasleyFooter]; |
| 577 [model setFooter:weasleyFooter | 561 [model setFooter:weasleyFooter |
| 578 forSectionWithIdentifier:SectionIdentifierWeasley]; | 562 forSectionWithIdentifier:SectionIdentifierWeasley]; |
| 579 | 563 |
| 580 NSInteger cheeseSection = | 564 NSInteger cheeseSection = |
| 581 [model sectionForSectionIdentifier:SectionIdentifierCheese]; | 565 [model sectionForSectionIdentifier:SectionIdentifierCheese]; |
| 582 NSInteger weasleySection = | 566 NSInteger weasleySection = |
| 583 [model sectionForSectionIdentifier:SectionIdentifierWeasley]; | 567 [model sectionForSectionIdentifier:SectionIdentifierWeasley]; |
| 584 | 568 |
| 585 EXPECT_FALSE([model footerForSectionWithIdentifier:SectionIdentifierCheese]); | 569 EXPECT_FALSE([model footerForSectionWithIdentifier:SectionIdentifierCheese]); |
| 586 EXPECT_FALSE([model footerForSection:cheeseSection]); | 570 EXPECT_FALSE([model footerForSection:cheeseSection]); |
| 587 | 571 |
| 588 EXPECT_EQ(weasleyFooter.get(), | 572 EXPECT_EQ(weasleyFooter, |
| 589 [model footerForSectionWithIdentifier:SectionIdentifierWeasley]); | 573 [model footerForSectionWithIdentifier:SectionIdentifierWeasley]); |
| 590 EXPECT_EQ(weasleyFooter.get(), [model footerForSection:weasleySection]); | 574 EXPECT_EQ(weasleyFooter, [model footerForSection:weasleySection]); |
| 591 } | 575 } |
| 592 | 576 |
| 593 } // namespace | 577 } // namespace |
| OLD | NEW |