This source file includes following definitions.
- TEST
- TEST
- TEST
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "device/nfc/nfc_ndef_record.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::DictionaryValue;
using base::ListValue;
using base::StringValue;
namespace device {
namespace {
const char kTestAction[] = "test-action";
const char kTestEncoding[] = "test-encoding";
const char kTestLanguageCode[] = "test-language-code";
const char kTestMimeType[] = "test-mime-type";
const uint32 kTestTargetSize = 0;
const char kTestText[] = "test-text";
const char kTestURI[] = "test://uri";
}
TEST(NfcNdefRecordTest, PopulateTextRecord) {
DictionaryValue data;
scoped_ptr<NfcNdefRecord> record(new NfcNdefRecord());
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeText, &data));
EXPECT_FALSE(record->IsPopulated());
data.SetInteger(NfcNdefRecord::kFieldText, 0);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeText, &data));
EXPECT_FALSE(record->IsPopulated());
data.SetString(NfcNdefRecord::kFieldText, kTestText);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeText, &data));
EXPECT_FALSE(record->IsPopulated());
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeText, &data));
data.SetInteger(NfcNdefRecord::kFieldLanguageCode, 0);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeText, &data));
EXPECT_FALSE(record->IsPopulated());
data.SetString(NfcNdefRecord::kFieldLanguageCode, kTestLanguageCode);
data.SetInteger(NfcNdefRecord::kFieldEncoding, 0);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeText, &data));
EXPECT_FALSE(record->IsPopulated());
data.SetString(NfcNdefRecord::kFieldEncoding, kTestEncoding);
EXPECT_TRUE(record->Populate(NfcNdefRecord::kTypeText, &data));
EXPECT_TRUE(record->IsPopulated());
EXPECT_EQ(NfcNdefRecord::kTypeText, record->type());
std::string string_value;
EXPECT_TRUE(record->data().GetString(
NfcNdefRecord::kFieldText, &string_value));
EXPECT_EQ(kTestText, string_value);
EXPECT_TRUE(record->data().GetString(
NfcNdefRecord::kFieldLanguageCode, &string_value));
EXPECT_EQ(kTestLanguageCode, string_value);
EXPECT_TRUE(record->data().GetString(
NfcNdefRecord::kFieldEncoding, &string_value));
EXPECT_EQ(kTestEncoding, string_value);
}
TEST(NfcNdefRecordTest, PopulateUriRecord) {
DictionaryValue data;
scoped_ptr<NfcNdefRecord> record(new NfcNdefRecord());
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeURI, &data));
EXPECT_FALSE(record->IsPopulated());
data.SetInteger(NfcNdefRecord::kFieldURI, 0);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeURI, &data));
EXPECT_FALSE(record->IsPopulated());
data.SetString(NfcNdefRecord::kFieldURI, "test.uri");
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeURI, &data));
EXPECT_FALSE(record->IsPopulated());
data.SetString(NfcNdefRecord::kFieldURI, kTestURI);
EXPECT_TRUE(record->Populate(NfcNdefRecord::kTypeURI, &data));
EXPECT_TRUE(record->IsPopulated());
EXPECT_EQ(NfcNdefRecord::kTypeURI, record->type());
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeURI, &data));
record.reset(new NfcNdefRecord());
EXPECT_FALSE(record->IsPopulated());
data.SetInteger(NfcNdefRecord::kFieldMimeType, 0);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeURI, &data));
EXPECT_FALSE(record->IsPopulated());
data.SetString(NfcNdefRecord::kFieldMimeType, kTestMimeType);
data.SetInteger(NfcNdefRecord::kFieldTargetSize, kTestTargetSize);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeURI, &data));
EXPECT_FALSE(record->IsPopulated());
data.SetDouble(NfcNdefRecord::kFieldTargetSize,
static_cast<double>(kTestTargetSize));
EXPECT_TRUE(record->Populate(NfcNdefRecord::kTypeURI, &data));
EXPECT_TRUE(record->IsPopulated());
EXPECT_EQ(NfcNdefRecord::kTypeURI, record->type());
std::string string_value;
double double_value;
EXPECT_TRUE(record->data().GetString(
NfcNdefRecord::kFieldURI, &string_value));
EXPECT_EQ(kTestURI, string_value);
EXPECT_TRUE(record->data().GetString(
NfcNdefRecord::kFieldMimeType, &string_value));
EXPECT_EQ(kTestMimeType, string_value);
EXPECT_TRUE(record->data().GetDouble(
NfcNdefRecord::kFieldTargetSize, &double_value));
EXPECT_EQ(kTestTargetSize, static_cast<uint32>(double_value));
}
TEST(NfcNdefRecordTest, PopulateSmartPoster) {
DictionaryValue data;
scoped_ptr<NfcNdefRecord> record(new NfcNdefRecord());
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data));
EXPECT_FALSE(record->IsPopulated());
data.SetInteger(NfcNdefRecord::kFieldURI, 0);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data));
EXPECT_FALSE(record->IsPopulated());
data.SetString(NfcNdefRecord::kFieldURI, kTestURI);
EXPECT_TRUE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data));
EXPECT_TRUE(record->IsPopulated());
EXPECT_EQ(NfcNdefRecord::kTypeSmartPoster, record->type());
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data));
record.reset(new NfcNdefRecord());
EXPECT_FALSE(record->IsPopulated());
data.SetInteger(NfcNdefRecord::kFieldAction, 0);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data));
EXPECT_FALSE(record->IsPopulated());
data.SetString(NfcNdefRecord::kFieldAction, kTestAction);
data.SetInteger(NfcNdefRecord::kFieldMimeType, 0);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data));
EXPECT_FALSE(record->IsPopulated());
data.SetString(NfcNdefRecord::kFieldMimeType, kTestMimeType);
data.SetInteger(NfcNdefRecord::kFieldTargetSize, kTestTargetSize);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data));
EXPECT_FALSE(record->IsPopulated());
data.SetDouble(NfcNdefRecord::kFieldTargetSize, kTestTargetSize);
data.SetInteger(NfcNdefRecord::kFieldTitles, 0);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data));
EXPECT_FALSE(record->IsPopulated());
ListValue* list_value = new ListValue();
data.Set(NfcNdefRecord::kFieldTitles, list_value);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data));
EXPECT_FALSE(record->IsPopulated());
DictionaryValue* title_value = new DictionaryValue();
list_value->Append(title_value);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data));
EXPECT_FALSE(record->IsPopulated());
title_value->SetInteger(NfcNdefRecord::kFieldText, 0);
EXPECT_FALSE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data));
EXPECT_FALSE(record->IsPopulated());
title_value->SetString(NfcNdefRecord::kFieldText, kTestText);
title_value->SetString(NfcNdefRecord::kFieldLanguageCode, kTestLanguageCode);
title_value->SetString(NfcNdefRecord::kFieldEncoding, kTestEncoding);
EXPECT_TRUE(record->Populate(NfcNdefRecord::kTypeSmartPoster, &data));
EXPECT_TRUE(record->IsPopulated());
std::string string_value;
double double_value;
const ListValue* const_list_value;
const DictionaryValue* const_dictionary_value;
EXPECT_TRUE(record->data().GetString(
NfcNdefRecord::kFieldURI, &string_value));
EXPECT_EQ(kTestURI, string_value);
EXPECT_TRUE(record->data().GetString(
NfcNdefRecord::kFieldMimeType, &string_value));
EXPECT_EQ(kTestMimeType, string_value);
EXPECT_TRUE(record->data().GetDouble(
NfcNdefRecord::kFieldTargetSize, &double_value));
EXPECT_EQ(kTestTargetSize, static_cast<uint32>(double_value));
EXPECT_TRUE(record->data().GetString(
NfcNdefRecord::kFieldAction, &string_value));
EXPECT_EQ(kTestAction, string_value);
EXPECT_TRUE(record->data().GetList(
NfcNdefRecord::kFieldTitles, &const_list_value));
EXPECT_EQ(static_cast<size_t>(1), const_list_value->GetSize());
EXPECT_TRUE(const_list_value->GetDictionary(0, &const_dictionary_value));
EXPECT_TRUE(const_dictionary_value->GetString(
NfcNdefRecord::kFieldText, &string_value));
EXPECT_EQ(kTestText, string_value);
EXPECT_TRUE(const_dictionary_value->GetString(
NfcNdefRecord::kFieldLanguageCode, &string_value));
EXPECT_EQ(kTestLanguageCode, string_value);
EXPECT_TRUE(const_dictionary_value->GetString(
NfcNdefRecord::kFieldEncoding, &string_value));
EXPECT_EQ(kTestEncoding, string_value);
}
}