Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / media_galleries / win / mtp_device_object_enumerator_unittest.cc
blobcc70b31e56126cd174d714be8d3b25046a25b1c3
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // MTPDeviceObjectEnumerator unit tests.
7 #include "chrome/browser/media_galleries/win/mtp_device_object_enumerator.h"
9 #include <ctime>
11 #include "base/basictypes.h"
12 #include "base/strings/string16.h"
13 #include "base/time/time.h"
14 #include "chrome/browser/media_galleries/win/mtp_device_object_entry.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace {
19 struct MTPDeviceObjectEntryData {
20 // Friendly name of the object, e.g. "IMG_9911.jpeg".
21 base::string16 name;
23 // The object identifier, e.g. "o299".
24 base::string16 object_id;
26 // True if the current object is a directory/folder/album content type.
27 bool is_directory;
29 // The object file size in bytes, e.g. "882992".
30 int64 size;
32 // Last modified time of the object.
33 time_t last_modified_time;
36 const MTPDeviceObjectEntryData kTestCases[] = {
37 { L"File_1", L"o100", false, 10023, 1121 },
38 { L"Directory_1", L"o52", true, 99833, 2231 },
39 { L"File_2", L"o230", false, 8733, 7372 },
42 void TestEnumeratorIsEmpty(MTPDeviceObjectEnumerator* enumerator) {
43 EXPECT_EQ(base::string16(), enumerator->GetObjectId());
44 EXPECT_EQ(0, enumerator->Size());
45 EXPECT_FALSE(enumerator->IsDirectory());
46 EXPECT_TRUE(enumerator->LastModifiedTime().is_null());
49 void TestNextEntryIsEmpty(MTPDeviceObjectEnumerator* enumerator) {
50 EXPECT_TRUE(enumerator->Next().empty());
53 typedef testing::Test MTPDeviceObjectEnumeratorWinTest;
55 TEST_F(MTPDeviceObjectEnumeratorWinTest, Empty) {
56 MTPDeviceObjectEntries entries;
57 MTPDeviceObjectEnumerator enumerator(entries);
58 TestEnumeratorIsEmpty(&enumerator);
59 TestNextEntryIsEmpty(&enumerator);
60 TestNextEntryIsEmpty(&enumerator);
61 TestEnumeratorIsEmpty(&enumerator);
64 TEST_F(MTPDeviceObjectEnumeratorWinTest, Traversal) {
65 MTPDeviceObjectEntries entries;
66 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
67 entries.push_back(MTPDeviceObjectEntry(
68 kTestCases[i].object_id,
69 kTestCases[i].name,
70 kTestCases[i].is_directory,
71 kTestCases[i].size,
72 base::Time::FromTimeT(kTestCases[i].last_modified_time)));
74 MTPDeviceObjectEnumerator enumerator(entries);
75 TestEnumeratorIsEmpty(&enumerator);
76 TestEnumeratorIsEmpty(&enumerator);
77 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
78 EXPECT_EQ(kTestCases[i].name, enumerator.Next().value());
79 EXPECT_EQ(kTestCases[i].object_id, enumerator.GetObjectId());
80 EXPECT_EQ(kTestCases[i].size, enumerator.Size());
81 EXPECT_EQ(kTestCases[i].is_directory, enumerator.IsDirectory());
82 EXPECT_EQ(kTestCases[i].last_modified_time,
83 enumerator.LastModifiedTime().ToTimeT());
85 TestNextEntryIsEmpty(&enumerator);
86 TestNextEntryIsEmpty(&enumerator);
87 TestEnumeratorIsEmpty(&enumerator);
88 TestNextEntryIsEmpty(&enumerator);
89 TestEnumeratorIsEmpty(&enumerator);
92 } // namespace