1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <algorithm>
18 #include <gtest/gtest.h>
19 #include <string>
20 #include <vector>
21 
22 #include "StringPiece.h"
23 
24 namespace aapt {
25 
TEST(StringPieceTest,CompareNonNullTerminatedPiece)26 TEST(StringPieceTest, CompareNonNullTerminatedPiece) {
27     StringPiece a("hello world", 5);
28     StringPiece b("hello moon", 5);
29     EXPECT_EQ(a, b);
30 
31     StringPiece16 a16(u"hello world", 5);
32     StringPiece16 b16(u"hello moon", 5);
33     EXPECT_EQ(a16, b16);
34 }
35 
TEST(StringPieceTest,PiecesHaveCorrectSortOrder)36 TEST(StringPieceTest, PiecesHaveCorrectSortOrder) {
37     std::u16string testing(u"testing");
38     std::u16string banana(u"banana");
39     std::u16string car(u"car");
40 
41     EXPECT_TRUE(StringPiece16(testing) > banana);
42     EXPECT_TRUE(StringPiece16(testing) > car);
43     EXPECT_TRUE(StringPiece16(banana) < testing);
44     EXPECT_TRUE(StringPiece16(banana) < car);
45     EXPECT_TRUE(StringPiece16(car) < testing);
46     EXPECT_TRUE(StringPiece16(car) > banana);
47 }
48 
TEST(StringPieceTest,PiecesHaveCorrectSortOrderUtf8)49 TEST(StringPieceTest, PiecesHaveCorrectSortOrderUtf8) {
50     std::string testing("testing");
51     std::string banana("banana");
52     std::string car("car");
53 
54     EXPECT_TRUE(StringPiece(testing) > banana);
55     EXPECT_TRUE(StringPiece(testing) > car);
56     EXPECT_TRUE(StringPiece(banana) < testing);
57     EXPECT_TRUE(StringPiece(banana) < car);
58     EXPECT_TRUE(StringPiece(car) < testing);
59     EXPECT_TRUE(StringPiece(car) > banana);
60 }
61 
62 } // namespace aapt
63