• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 #include "mojo/public/cpp/bindings/string.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 
8 namespace mojo {
9 namespace test {
10 
TEST(StringTest,DefaultIsNull)11 TEST(StringTest, DefaultIsNull) {
12   String s;
13   EXPECT_TRUE(s.is_null());
14 }
15 
TEST(StringTest,ConstructedWithNULL)16 TEST(StringTest, ConstructedWithNULL) {
17   String s(NULL);
18   EXPECT_TRUE(s.is_null());
19 }
20 
TEST(StringTest,ConstructedWithNullCharPointer)21 TEST(StringTest, ConstructedWithNullCharPointer) {
22   const char* null = NULL;
23   String s(null);
24   EXPECT_TRUE(s.is_null());
25 }
26 
TEST(StringTest,AssignedNULL)27 TEST(StringTest, AssignedNULL) {
28   String s("");
29   EXPECT_FALSE(s.is_null());
30   s = NULL;
31   EXPECT_TRUE(s.is_null());
32 }
33 
TEST(StringTest,Empty)34 TEST(StringTest, Empty) {
35   String s("");
36   EXPECT_FALSE(s.is_null());
37   EXPECT_TRUE(s.get().empty());
38 }
39 
TEST(StringTest,Basic)40 TEST(StringTest, Basic) {
41   String s("hello world");
42   EXPECT_EQ(std::string("hello world"), s.get());
43 }
44 
TEST(StringTest,Assignment)45 TEST(StringTest, Assignment) {
46   String s("hello world");
47   String t = s;  // Makes a copy.
48   EXPECT_FALSE(t.is_null());
49   EXPECT_EQ(std::string("hello world"), t.get());
50   EXPECT_FALSE(s.is_null());
51 }
52 
TEST(StringTest,Equality)53 TEST(StringTest, Equality) {
54   String s("hello world");
55   String t("hello world");
56   EXPECT_EQ(s, t);
57   EXPECT_TRUE(s == t);
58   EXPECT_TRUE("hello world" == s);
59   EXPECT_TRUE(s == "hello world");
60   EXPECT_TRUE("not" != s);
61   EXPECT_TRUE(s != "not");
62 }
63 
64 }  // namespace test
65 }  // namespace mojo
66