This source file includes following definitions.
- ExpectEqualsStringPiece
- ExpectEqualsMojoString
- ExpectEqualsString16
- ExpectEqualsMojoString
- TEST
- TEST
#include "mojo/common/common_type_converters.h"
#include "base/strings/utf_string_conversions.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
namespace common {
namespace test {
namespace {
void ExpectEqualsStringPiece(const std::string& expected,
const base::StringPiece& str) {
EXPECT_EQ(expected, str.as_string());
}
void ExpectEqualsMojoString(const std::string& expected,
const String& str) {
EXPECT_EQ(expected, str.To<std::string>());
}
void ExpectEqualsString16(const base::string16& expected,
const base::string16& actual) {
EXPECT_EQ(expected, actual);
}
void ExpectEqualsMojoString(const base::string16& expected,
const String& str) {
EXPECT_EQ(expected, str.To<base::string16>());
}
}
TEST(CommonTypeConvertersTest, StringPiece) {
AllocationScope scope;
std::string kText("hello world");
base::StringPiece string_piece(kText);
String mojo_string(string_piece);
ExpectEqualsMojoString(kText, mojo_string);
ExpectEqualsStringPiece(kText, mojo_string.To<base::StringPiece>());
ExpectEqualsMojoString(kText, string_piece);
ExpectEqualsStringPiece(kText, mojo_string);
base::StringPiece empty_string_piece = String();
EXPECT_TRUE(empty_string_piece.empty());
}
TEST(CommonTypeConvertersTest, String16) {
AllocationScope scope;
const base::string16 string16(base::ASCIIToUTF16("hello world"));
const String mojo_string(string16);
ExpectEqualsMojoString(string16, mojo_string);
EXPECT_EQ(string16, mojo_string.To<base::string16>());
ExpectEqualsMojoString(string16, string16);
ExpectEqualsString16(string16, mojo_string);
ExpectEqualsMojoString(base::string16(), base::string16());
}
}
}
}