OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "device/nfc/nfc_ndef_record.h" |
| 6 |
5 #include <stddef.h> | 7 #include <stddef.h> |
6 #include <stdint.h> | 8 #include <stdint.h> |
7 | 9 |
8 #include "base/memory/scoped_ptr.h" | 10 #include <memory> |
| 11 |
9 #include "base/values.h" | 12 #include "base/values.h" |
10 #include "device/nfc/nfc_ndef_record.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 using base::DictionaryValue; | 15 using base::DictionaryValue; |
14 using base::ListValue; | 16 using base::ListValue; |
15 using base::StringValue; | 17 using base::StringValue; |
16 | 18 |
17 namespace device { | 19 namespace device { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 const char kTestAction[] = "test-action"; | 23 const char kTestAction[] = "test-action"; |
22 const char kTestEncoding[] = "test-encoding"; | 24 const char kTestEncoding[] = "test-encoding"; |
23 const char kTestLanguageCode[] = "test-language-code"; | 25 const char kTestLanguageCode[] = "test-language-code"; |
24 const char kTestMimeType[] = "test-mime-type"; | 26 const char kTestMimeType[] = "test-mime-type"; |
25 const uint32_t kTestTargetSize = 0; | 27 const uint32_t kTestTargetSize = 0; |
26 const char kTestText[] = "test-text"; | 28 const char kTestText[] = "test-text"; |
27 const char kTestURI[] = "test://uri"; | 29 const char kTestURI[] = "test://uri"; |
28 | 30 |
29 } // namespace | 31 } // namespace |
30 | 32 |
31 TEST(NfcNdefRecordTest, PopulateTextRecord) { | 33 TEST(NfcNdefRecordTest, PopulateTextRecord) { |
32 DictionaryValue data; | 34 DictionaryValue data; |
33 scoped_ptr<NfcNdefRecord> record(new NfcNdefRecord()); | 35 std::unique_ptr<NfcNdefRecord> record(new NfcNdefRecord()); |
34 | 36 |
35 // Missing text field. Should fail. | 37 // Missing text field. Should fail. |
36 EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeText, &data)); | 38 EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeText, &data)); |
37 EXPECT_FALSE(record->IsPopulated()); | 39 EXPECT_FALSE(record->IsPopulated()); |
38 | 40 |
39 // Text field with incorrect type. Should fail. | 41 // Text field with incorrect type. Should fail. |
40 data.SetInteger(NfcNdefRecord::kFieldText, 0); | 42 data.SetInteger(NfcNdefRecord::kFieldText, 0); |
41 EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeText, &data)); | 43 EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeText, &data)); |
42 EXPECT_FALSE(record->IsPopulated()); | 44 EXPECT_FALSE(record->IsPopulated()); |
43 | 45 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 EXPECT_TRUE(record->data().GetString( | 77 EXPECT_TRUE(record->data().GetString( |
76 NfcNdefRecord::kFieldLanguageCode, &string_value)); | 78 NfcNdefRecord::kFieldLanguageCode, &string_value)); |
77 EXPECT_EQ(kTestLanguageCode, string_value); | 79 EXPECT_EQ(kTestLanguageCode, string_value); |
78 EXPECT_TRUE(record->data().GetString( | 80 EXPECT_TRUE(record->data().GetString( |
79 NfcNdefRecord::kFieldEncoding, &string_value)); | 81 NfcNdefRecord::kFieldEncoding, &string_value)); |
80 EXPECT_EQ(kTestEncoding, string_value); | 82 EXPECT_EQ(kTestEncoding, string_value); |
81 } | 83 } |
82 | 84 |
83 TEST(NfcNdefRecordTest, PopulateUriRecord) { | 85 TEST(NfcNdefRecordTest, PopulateUriRecord) { |
84 DictionaryValue data; | 86 DictionaryValue data; |
85 scoped_ptr<NfcNdefRecord> record(new NfcNdefRecord()); | 87 std::unique_ptr<NfcNdefRecord> record(new NfcNdefRecord()); |
86 | 88 |
87 // Missing URI field. Should fail. | 89 // Missing URI field. Should fail. |
88 EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeURI, &data)); | 90 EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeURI, &data)); |
89 EXPECT_FALSE(record->IsPopulated()); | 91 EXPECT_FALSE(record->IsPopulated()); |
90 | 92 |
91 // URI field with incorrect type. Should fail. | 93 // URI field with incorrect type. Should fail. |
92 data.SetInteger(NfcNdefRecord::kFieldURI, 0); | 94 data.SetInteger(NfcNdefRecord::kFieldURI, 0); |
93 EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeURI, &data)); | 95 EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeURI, &data)); |
94 EXPECT_FALSE(record->IsPopulated()); | 96 EXPECT_FALSE(record->IsPopulated()); |
95 | 97 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 EXPECT_TRUE(record->data().GetString( | 138 EXPECT_TRUE(record->data().GetString( |
137 NfcNdefRecord::kFieldMimeType, &string_value)); | 139 NfcNdefRecord::kFieldMimeType, &string_value)); |
138 EXPECT_EQ(kTestMimeType, string_value); | 140 EXPECT_EQ(kTestMimeType, string_value); |
139 EXPECT_TRUE(record->data().GetDouble( | 141 EXPECT_TRUE(record->data().GetDouble( |
140 NfcNdefRecord::kFieldTargetSize, &double_value)); | 142 NfcNdefRecord::kFieldTargetSize, &double_value)); |
141 EXPECT_EQ(kTestTargetSize, static_cast<uint32_t>(double_value)); | 143 EXPECT_EQ(kTestTargetSize, static_cast<uint32_t>(double_value)); |
142 } | 144 } |
143 | 145 |
144 TEST(NfcNdefRecordTest, PopulateSmartPoster) { | 146 TEST(NfcNdefRecordTest, PopulateSmartPoster) { |
145 DictionaryValue data; | 147 DictionaryValue data; |
146 scoped_ptr<NfcNdefRecord> record(new NfcNdefRecord()); | 148 std::unique_ptr<NfcNdefRecord> record(new NfcNdefRecord()); |
147 | 149 |
148 // Missing URI field. Should fail. | 150 // Missing URI field. Should fail. |
149 EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data)); | 151 EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data)); |
150 EXPECT_FALSE(record->IsPopulated()); | 152 EXPECT_FALSE(record->IsPopulated()); |
151 | 153 |
152 // URI field with incorrect entry. Should fail. | 154 // URI field with incorrect entry. Should fail. |
153 data.SetInteger(NfcNdefRecord::kFieldURI, 0); | 155 data.SetInteger(NfcNdefRecord::kFieldURI, 0); |
154 EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data)); | 156 EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data)); |
155 EXPECT_FALSE(record->IsPopulated()); | 157 EXPECT_FALSE(record->IsPopulated()); |
156 | 158 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 EXPECT_EQ(kTestText, string_value); | 243 EXPECT_EQ(kTestText, string_value); |
242 EXPECT_TRUE(const_dictionary_value->GetString( | 244 EXPECT_TRUE(const_dictionary_value->GetString( |
243 NfcNdefRecord::kFieldLanguageCode, &string_value)); | 245 NfcNdefRecord::kFieldLanguageCode, &string_value)); |
244 EXPECT_EQ(kTestLanguageCode, string_value); | 246 EXPECT_EQ(kTestLanguageCode, string_value); |
245 EXPECT_TRUE(const_dictionary_value->GetString( | 247 EXPECT_TRUE(const_dictionary_value->GetString( |
246 NfcNdefRecord::kFieldEncoding, &string_value)); | 248 NfcNdefRecord::kFieldEncoding, &string_value)); |
247 EXPECT_EQ(kTestEncoding, string_value); | 249 EXPECT_EQ(kTestEncoding, string_value); |
248 } | 250 } |
249 | 251 |
250 } // namespace device | 252 } // namespace device |
OLD | NEW |