Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: ios/chrome/browser/ui/collection_view/collection_view_model_unittest.mm

Issue 2638763004: Report CHECK/DCHECK to test launcher summary output. (Closed)
Patch Set: Add test for assert handlers nesting. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/common/logging_chrome.cc ('k') | net/test/scoped_disable_exit_on_dfatal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bind.h"
8 #include "base/logging.h"
7 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/strings/string_piece.h"
8 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 11 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
9 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/gtest_mac.h" 13 #include "testing/gtest_mac.h"
11 14
12 #if !defined(__has_feature) || !__has_feature(objc_arc) 15 #if !defined(__has_feature) || !__has_feature(objc_arc)
13 #error "This file requires ARC support." 16 #error "This file requires ARC support."
14 #endif 17 #endif
15 18
16 @interface CollectionViewModel (Testing) 19 @interface CollectionViewModel (Testing)
17 // Adds an item with the given type to the section with the given identifier. 20 // Adds an item with the given type to the section with the given identifier.
(...skipping 29 matching lines...) Expand all
47 ItemTypeCheeseHeader = kItemTypeEnumZero, 50 ItemTypeCheeseHeader = kItemTypeEnumZero,
48 ItemTypeCheeseCheddar, 51 ItemTypeCheeseCheddar,
49 ItemTypeCheeseGouda, 52 ItemTypeCheeseGouda,
50 ItemTypeCheesePepperJack, 53 ItemTypeCheesePepperJack,
51 ItemTypeWeasleyRon, 54 ItemTypeWeasleyRon,
52 ItemTypeWeasleyGinny, 55 ItemTypeWeasleyGinny,
53 ItemTypeWeasleyArthur, 56 ItemTypeWeasleyArthur,
54 ItemTypeWeasleyFooter, 57 ItemTypeWeasleyFooter,
55 }; 58 };
56 59
57 void LogSink(const std::string& str) { 60 void LogSink(const char* file,
61 int line,
62 const base::StringPiece message,
63 const base::StringPiece stack_trace) {
58 // No-op. 64 // No-op.
59 } 65 }
60 66
61 // Test generic model boxing (check done at compilation time). 67 // Test generic model boxing (check done at compilation time).
62 TEST(CollectionViewModelTest, GenericModelBoxing) { 68 TEST(CollectionViewModelTest, GenericModelBoxing) {
63 CollectionViewModel<TestCollectionViewItemSubclass*>* specificModel = 69 CollectionViewModel<TestCollectionViewItemSubclass*>* specificModel =
64 [[CollectionViewModel alloc] init]; 70 [[CollectionViewModel alloc] init];
65 71
66 // |generalModel| is a superclass of |specificModel|. So specificModel can be 72 // |generalModel| is a superclass of |specificModel|. So specificModel can be
67 // boxed into generalModel, but not the other way around. 73 // boxed into generalModel, but not the other way around.
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 EXPECT_EQ(3U, [cheeseItems count]); 311 EXPECT_EQ(3U, [cheeseItems count]);
306 EXPECT_NSEQ(cheddar, cheeseItems[0]); 312 EXPECT_NSEQ(cheddar, cheeseItems[0]);
307 EXPECT_NSEQ(pepperJack, cheeseItems[1]); 313 EXPECT_NSEQ(pepperJack, cheeseItems[1]);
308 EXPECT_NSEQ(gouda, cheeseItems[2]); 314 EXPECT_NSEQ(gouda, cheeseItems[2]);
309 } 315 }
310 316
311 TEST(CollectionViewModelTest, InvalidIndexPath) { 317 TEST(CollectionViewModelTest, InvalidIndexPath) {
312 CollectionViewModel* model = [[CollectionViewModel alloc] init]; 318 CollectionViewModel* model = [[CollectionViewModel alloc] init];
313 [model addSectionWithIdentifier:SectionIdentifierCheese]; 319 [model addSectionWithIdentifier:SectionIdentifierCheese];
314 320
315 logging::SetLogAssertHandler(&LogSink); 321 logging::ScopedLogAssertHandler scoped_assert_handler(base::Bind(LogSink));
316 bool out_of_bounds_exception_thrown = false; 322 bool out_of_bounds_exception_thrown = false;
317 @try { 323 @try {
318 [model indexInItemTypeForIndexPath:[NSIndexPath indexPathForItem:0 324 [model indexInItemTypeForIndexPath:[NSIndexPath indexPathForItem:0
319 inSection:0]]; 325 inSection:0]];
320 } @catch (NSException* exception) { 326 } @catch (NSException* exception) {
321 if ([[exception name] isEqualToString:NSRangeException]) { 327 if ([[exception name] isEqualToString:NSRangeException]) {
322 out_of_bounds_exception_thrown = true; 328 out_of_bounds_exception_thrown = true;
323 } 329 }
324 } 330 }
325 EXPECT_TRUE(out_of_bounds_exception_thrown); 331 EXPECT_TRUE(out_of_bounds_exception_thrown);
326 logging::SetLogAssertHandler(nullptr);
327 } 332 }
328 333
329 TEST(CollectionViewModelTest, RemoveItems) { 334 TEST(CollectionViewModelTest, RemoveItems) {
330 CollectionViewModel* model = [[CollectionViewModel alloc] init]; 335 CollectionViewModel* model = [[CollectionViewModel alloc] init];
331 336
332 [model addSectionWithIdentifier:SectionIdentifierCheese]; 337 [model addSectionWithIdentifier:SectionIdentifierCheese];
333 [model addItemWithType:ItemTypeCheesePepperJack 338 [model addItemWithType:ItemTypeCheesePepperJack
334 toSectionWithIdentifier:SectionIdentifierCheese]; 339 toSectionWithIdentifier:SectionIdentifierCheese];
335 [model addItemWithType:ItemTypeCheeseGouda 340 [model addItemWithType:ItemTypeCheeseGouda
336 toSectionWithIdentifier:SectionIdentifierCheese]; 341 toSectionWithIdentifier:SectionIdentifierCheese];
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 590
586 EXPECT_FALSE([model footerForSectionWithIdentifier:SectionIdentifierCheese]); 591 EXPECT_FALSE([model footerForSectionWithIdentifier:SectionIdentifierCheese]);
587 EXPECT_FALSE([model footerForSection:cheeseSection]); 592 EXPECT_FALSE([model footerForSection:cheeseSection]);
588 593
589 EXPECT_EQ(weasleyFooter, 594 EXPECT_EQ(weasleyFooter,
590 [model footerForSectionWithIdentifier:SectionIdentifierWeasley]); 595 [model footerForSectionWithIdentifier:SectionIdentifierWeasley]);
591 EXPECT_EQ(weasleyFooter, [model footerForSection:weasleySection]); 596 EXPECT_EQ(weasleyFooter, [model footerForSection:weasleySection]);
592 } 597 }
593 598
594 } // namespace 599 } // namespace
OLDNEW
« no previous file with comments | « chrome/common/logging_chrome.cc ('k') | net/test/scoped_disable_exit_on_dfatal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698