blob: 822e527253df4f9b3ed3e9c15d900bc4e2af9543 [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -08001/*
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
Adam Lesinskid5083f62017-01-16 15:07:21 -080017#include "androidfw/StringPiece.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070018
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080019#include <algorithm>
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080020#include <string>
21#include <vector>
22
Adam Lesinskid5083f62017-01-16 15:07:21 -080023#include "TestHelpers.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080024
Adam Lesinskid5083f62017-01-16 15:07:21 -080025namespace android {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080026
27TEST(StringPieceTest, CompareNonNullTerminatedPiece) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070028 StringPiece a("hello world", 5);
29 StringPiece b("hello moon", 5);
30 EXPECT_EQ(a, b);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080031
Adam Lesinskice5e56e2016-10-21 17:56:45 -070032 StringPiece16 a16(u"hello world", 5);
33 StringPiece16 b16(u"hello moon", 5);
34 EXPECT_EQ(a16, b16);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080035}
36
37TEST(StringPieceTest, PiecesHaveCorrectSortOrder) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070038 std::string testing("testing");
39 std::string banana("banana");
40 std::string car("car");
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080041
Adam Lesinskice5e56e2016-10-21 17:56:45 -070042 EXPECT_TRUE(StringPiece(testing) > banana);
43 EXPECT_TRUE(StringPiece(testing) > car);
44 EXPECT_TRUE(StringPiece(banana) < testing);
45 EXPECT_TRUE(StringPiece(banana) < car);
46 EXPECT_TRUE(StringPiece(car) < testing);
47 EXPECT_TRUE(StringPiece(car) > banana);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080048}
49
50TEST(StringPieceTest, PiecesHaveCorrectSortOrderUtf8) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070051 std::string testing("testing");
52 std::string banana("banana");
53 std::string car("car");
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080054
Adam Lesinskice5e56e2016-10-21 17:56:45 -070055 EXPECT_TRUE(StringPiece(testing) > banana);
56 EXPECT_TRUE(StringPiece(testing) > car);
57 EXPECT_TRUE(StringPiece(banana) < testing);
58 EXPECT_TRUE(StringPiece(banana) < car);
59 EXPECT_TRUE(StringPiece(car) < testing);
60 EXPECT_TRUE(StringPiece(car) > banana);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080061}
62
Adam Lesinskid5083f62017-01-16 15:07:21 -080063} // namespace android