blob: 58a03de60f931fda233f672cbbb0d07c24eefe0b [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
17#include "StringPool.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080018
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080019#include <string>
20
Adam Lesinskid5083f62017-01-16 15:07:21 -080021#include "androidfw/StringPiece.h"
22
Ryan Mitchell70414f22018-03-26 11:05:31 -070023#include "Diagnostics.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070024#include "test/Test.h"
25#include "util/Util.h"
26
Adam Lesinski060b53d2017-07-28 17:10:35 -070027using ::android::StringPiece;
28using ::android::StringPiece16;
29using ::testing::Eq;
30using ::testing::Ne;
31using ::testing::NotNull;
32using ::testing::Pointee;
Adam Lesinskid5083f62017-01-16 15:07:21 -080033
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080034namespace aapt {
35
36TEST(StringPoolTest, InsertOneString) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070037 StringPool pool;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080038
Adam Lesinskice5e56e2016-10-21 17:56:45 -070039 StringPool::Ref ref = pool.MakeRef("wut");
Adam Lesinski060b53d2017-07-28 17:10:35 -070040 EXPECT_THAT(*ref, Eq("wut"));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080041}
42
43TEST(StringPoolTest, InsertTwoUniqueStrings) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070044 StringPool pool;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080045
Adam Lesinski060b53d2017-07-28 17:10:35 -070046 StringPool::Ref ref_a = pool.MakeRef("wut");
47 StringPool::Ref ref_b = pool.MakeRef("hey");
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080048
Adam Lesinski060b53d2017-07-28 17:10:35 -070049 EXPECT_THAT(*ref_a, Eq("wut"));
50 EXPECT_THAT(*ref_b, Eq("hey"));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080051}
52
53TEST(StringPoolTest, DoNotInsertNewDuplicateString) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070054 StringPool pool;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080055
Adam Lesinski060b53d2017-07-28 17:10:35 -070056 StringPool::Ref ref_a = pool.MakeRef("wut");
57 StringPool::Ref ref_b = pool.MakeRef("wut");
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080058
Adam Lesinski060b53d2017-07-28 17:10:35 -070059 EXPECT_THAT(*ref_a, Eq("wut"));
60 EXPECT_THAT(*ref_b, Eq("wut"));
61 EXPECT_THAT(pool.size(), Eq(1u));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080062}
63
64TEST(StringPoolTest, MaintainInsertionOrderIndex) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070065 StringPool pool;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080066
Adam Lesinski060b53d2017-07-28 17:10:35 -070067 StringPool::Ref ref_a = pool.MakeRef("z");
68 StringPool::Ref ref_b = pool.MakeRef("a");
69 StringPool::Ref ref_c = pool.MakeRef("m");
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080070
Adam Lesinski060b53d2017-07-28 17:10:35 -070071 EXPECT_THAT(ref_a.index(), Eq(0u));
72 EXPECT_THAT(ref_b.index(), Eq(1u));
73 EXPECT_THAT(ref_c.index(), Eq(2u));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080074}
75
76TEST(StringPoolTest, PruneStringsWithNoReferences) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070077 StringPool pool;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080078
Adam Lesinski060b53d2017-07-28 17:10:35 -070079 StringPool::Ref ref_a = pool.MakeRef("foo");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070080
Adam Lesinski060b53d2017-07-28 17:10:35 -070081 {
82 StringPool::Ref ref_b = pool.MakeRef("wut");
83 EXPECT_THAT(*ref_b, Eq("wut"));
84 EXPECT_THAT(pool.size(), Eq(2u));
85 pool.Prune();
86 EXPECT_THAT(pool.size(), Eq(2u));
87 }
88 EXPECT_THAT(pool.size(), Eq(2u));
89
90 {
91 StringPool::Ref ref_c = pool.MakeRef("bar");
92 EXPECT_THAT(pool.size(), Eq(3u));
93
94 pool.Prune();
95 EXPECT_THAT(pool.size(), Eq(2u));
96 }
97 EXPECT_THAT(pool.size(), Eq(2u));
98
Adam Lesinskice5e56e2016-10-21 17:56:45 -070099 pool.Prune();
Adam Lesinski060b53d2017-07-28 17:10:35 -0700100 EXPECT_THAT(pool.size(), Eq(1u));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800101}
102
Adam Lesinski060b53d2017-07-28 17:10:35 -0700103TEST(StringPoolTest, SortAndMaintainIndexesInStringReferences) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700104 StringPool pool;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800105
Adam Lesinski060b53d2017-07-28 17:10:35 -0700106 StringPool::Ref ref_a = pool.MakeRef("z");
107 StringPool::Ref ref_b = pool.MakeRef("a");
108 StringPool::Ref ref_c = pool.MakeRef("m");
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800109
Adam Lesinski060b53d2017-07-28 17:10:35 -0700110 EXPECT_THAT(*ref_a, Eq("z"));
111 EXPECT_THAT(ref_a.index(), Eq(0u));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800112
Adam Lesinski060b53d2017-07-28 17:10:35 -0700113 EXPECT_THAT(*ref_b, Eq("a"));
114 EXPECT_THAT(ref_b.index(), Eq(1u));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800115
Adam Lesinski060b53d2017-07-28 17:10:35 -0700116 EXPECT_THAT(*ref_c, Eq("m"));
117 EXPECT_THAT(ref_c.index(), Eq(2u));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800118
Adam Lesinski060b53d2017-07-28 17:10:35 -0700119 pool.Sort();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800120
Adam Lesinski060b53d2017-07-28 17:10:35 -0700121 EXPECT_THAT(*ref_a, Eq("z"));
122 EXPECT_THAT(ref_a.index(), Eq(2u));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800123
Adam Lesinski060b53d2017-07-28 17:10:35 -0700124 EXPECT_THAT(*ref_b, Eq("a"));
125 EXPECT_THAT(ref_b.index(), Eq(0u));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800126
Adam Lesinski060b53d2017-07-28 17:10:35 -0700127 EXPECT_THAT(*ref_c, Eq("m"));
128 EXPECT_THAT(ref_c.index(), Eq(1u));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800129}
130
131TEST(StringPoolTest, SortAndStillDedupe) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700132 StringPool pool;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800133
Adam Lesinski060b53d2017-07-28 17:10:35 -0700134 StringPool::Ref ref_a = pool.MakeRef("z");
135 StringPool::Ref ref_b = pool.MakeRef("a");
136 StringPool::Ref ref_c = pool.MakeRef("m");
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800137
Adam Lesinski060b53d2017-07-28 17:10:35 -0700138 pool.Sort();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800139
Adam Lesinski060b53d2017-07-28 17:10:35 -0700140 StringPool::Ref ref_d = pool.MakeRef("z");
141 StringPool::Ref ref_e = pool.MakeRef("a");
142 StringPool::Ref ref_f = pool.MakeRef("m");
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800143
Adam Lesinski060b53d2017-07-28 17:10:35 -0700144 EXPECT_THAT(ref_d.index(), Eq(ref_a.index()));
145 EXPECT_THAT(ref_e.index(), Eq(ref_b.index()));
146 EXPECT_THAT(ref_f.index(), Eq(ref_c.index()));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800147}
148
149TEST(StringPoolTest, AddStyles) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700150 StringPool pool;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800151
Adam Lesinski060b53d2017-07-28 17:10:35 -0700152 StringPool::StyleRef ref = pool.MakeRef(StyleString{{"android"}, {Span{{"b"}, 2, 6}}});
153 EXPECT_THAT(ref.index(), Eq(0u));
154 EXPECT_THAT(ref->value, Eq("android"));
155 ASSERT_THAT(ref->spans.size(), Eq(1u));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800156
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700157 const StringPool::Span& span = ref->spans.front();
Adam Lesinski060b53d2017-07-28 17:10:35 -0700158 EXPECT_THAT(*span.name, Eq("b"));
159 EXPECT_THAT(span.first_char, Eq(2u));
160 EXPECT_THAT(span.last_char, Eq(6u));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800161}
162
163TEST(StringPoolTest, DoNotDedupeStyleWithSameStringAsNonStyle) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700164 StringPool pool;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800165
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700166 StringPool::Ref ref = pool.MakeRef("android");
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800167
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700168 StyleString str{{"android"}};
Adam Lesinski060b53d2017-07-28 17:10:35 -0700169 StringPool::StyleRef style_ref = pool.MakeRef(StyleString{{"android"}});
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800170
Adam Lesinski060b53d2017-07-28 17:10:35 -0700171 EXPECT_THAT(ref.index(), Ne(style_ref.index()));
172}
173
174TEST(StringPoolTest, StylesAndStringsAreSeparateAfterSorting) {
175 StringPool pool;
176
177 StringPool::StyleRef ref_a = pool.MakeRef(StyleString{{"beta"}});
178 StringPool::Ref ref_b = pool.MakeRef("alpha");
179 StringPool::StyleRef ref_c = pool.MakeRef(StyleString{{"alpha"}});
180
181 EXPECT_THAT(ref_b.index(), Ne(ref_c.index()));
182
183 pool.Sort();
184
185 EXPECT_THAT(ref_c.index(), Eq(0u));
186 EXPECT_THAT(ref_a.index(), Eq(1u));
187 EXPECT_THAT(ref_b.index(), Eq(2u));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800188}
189
Adam Lesinski769de982015-04-10 19:43:55 -0700190TEST(StringPoolTest, FlattenEmptyStringPoolUtf8) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700191 using namespace android; // For NO_ERROR on Windows.
Ryan Mitchell70414f22018-03-26 11:05:31 -0700192 StdErrDiagnostics diag;
Adam Lesinski803c7c82016-04-06 16:09:43 -0700193
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700194 StringPool pool;
195 BigBuffer buffer(1024);
Ryan Mitchell70414f22018-03-26 11:05:31 -0700196 StringPool::FlattenUtf8(&buffer, pool, &diag);
Adam Lesinski769de982015-04-10 19:43:55 -0700197
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700198 std::unique_ptr<uint8_t[]> data = util::Copy(buffer);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700199 ResStringPool test;
Adam Lesinski060b53d2017-07-28 17:10:35 -0700200 ASSERT_THAT(test.setTo(data.get(), buffer.size()), Eq(NO_ERROR));
Adam Lesinski769de982015-04-10 19:43:55 -0700201}
202
Adam Lesinski52364f72016-01-11 13:10:24 -0800203TEST(StringPoolTest, FlattenOddCharactersUtf16) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700204 using namespace android; // For NO_ERROR on Windows.
Ryan Mitchell70414f22018-03-26 11:05:31 -0700205 StdErrDiagnostics diag;
Adam Lesinski803c7c82016-04-06 16:09:43 -0700206
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700207 StringPool pool;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700208 pool.MakeRef("\u093f");
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700209 BigBuffer buffer(1024);
Ryan Mitchell70414f22018-03-26 11:05:31 -0700210 StringPool::FlattenUtf16(&buffer, pool, &diag);
Adam Lesinski52364f72016-01-11 13:10:24 -0800211
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700212 std::unique_ptr<uint8_t[]> data = util::Copy(buffer);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700213 ResStringPool test;
214 ASSERT_EQ(test.setTo(data.get(), buffer.size()), NO_ERROR);
215 size_t len = 0;
216 const char16_t* str = test.stringAt(0, &len);
Adam Lesinski060b53d2017-07-28 17:10:35 -0700217 EXPECT_THAT(len, Eq(1u));
218 EXPECT_THAT(str, Pointee(Eq(u'\u093f')));
219 EXPECT_THAT(str[1], Eq(0u));
Adam Lesinski52364f72016-01-11 13:10:24 -0800220}
221
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700222constexpr const char* sLongString =
223 "バッテリーを長持ちさせるため、バッテリーセーバーは端末のパフォーマンスを抑"
224 "え、バイブレーション、位置情報サービス、大半のバックグラウンドデータを制限"
225 "します。メール、SMSや、同期を使 "
226 "用するその他のアプリは、起動しても更新されないことがあります。バッテリーセ"
227 "ーバーは端末の充電中は自動的にOFFになります。";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800228
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700229TEST(StringPoolTest, Flatten) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700230 using namespace android; // For NO_ERROR on Windows.
Ryan Mitchell70414f22018-03-26 11:05:31 -0700231 StdErrDiagnostics diag;
Adam Lesinski803c7c82016-04-06 16:09:43 -0700232
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700233 StringPool pool;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800234
Adam Lesinski060b53d2017-07-28 17:10:35 -0700235 StringPool::Ref ref_a = pool.MakeRef("hello");
236 StringPool::Ref ref_b = pool.MakeRef("goodbye");
237 StringPool::Ref ref_c = pool.MakeRef(sLongString);
238 StringPool::Ref ref_d = pool.MakeRef("");
239 StringPool::StyleRef ref_e =
240 pool.MakeRef(StyleString{{"style"}, {Span{{"b"}, 0, 1}, Span{{"i"}, 2, 3}}});
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800241
Adam Lesinski060b53d2017-07-28 17:10:35 -0700242 // Styles are always first.
243 EXPECT_THAT(ref_e.index(), Eq(0u));
244
245 EXPECT_THAT(ref_a.index(), Eq(1u));
246 EXPECT_THAT(ref_b.index(), Eq(2u));
247 EXPECT_THAT(ref_c.index(), Eq(3u));
248 EXPECT_THAT(ref_d.index(), Eq(4u));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800249
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700250 BigBuffer buffers[2] = {BigBuffer(1024), BigBuffer(1024)};
Ryan Mitchell70414f22018-03-26 11:05:31 -0700251 StringPool::FlattenUtf8(&buffers[0], pool, &diag);
252 StringPool::FlattenUtf16(&buffers[1], pool, &diag);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800253
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700254 // Test both UTF-8 and UTF-16 buffers.
255 for (const BigBuffer& buffer : buffers) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700256 std::unique_ptr<uint8_t[]> data = util::Copy(buffer);
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700257
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700258 ResStringPool test;
259 ASSERT_EQ(test.setTo(data.get(), buffer.size()), NO_ERROR);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800260
Adam Lesinski060b53d2017-07-28 17:10:35 -0700261 EXPECT_THAT(util::GetString(test, 1), Eq("hello"));
262 EXPECT_THAT(util::GetString16(test, 1), Eq(u"hello"));
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700263
Adam Lesinski060b53d2017-07-28 17:10:35 -0700264 EXPECT_THAT(util::GetString(test, 2), Eq("goodbye"));
265 EXPECT_THAT(util::GetString16(test, 2), Eq(u"goodbye"));
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700266
Adam Lesinski060b53d2017-07-28 17:10:35 -0700267 EXPECT_THAT(util::GetString(test, 3), Eq(sLongString));
268 EXPECT_THAT(util::GetString16(test, 3), Eq(util::Utf8ToUtf16(sLongString)));
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700269
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700270 size_t len;
Adam Lesinski060b53d2017-07-28 17:10:35 -0700271 EXPECT_TRUE(test.stringAt(4, &len) != nullptr || test.string8At(4, &len) != nullptr);
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700272
Adam Lesinski060b53d2017-07-28 17:10:35 -0700273 EXPECT_THAT(util::GetString(test, 0), Eq("style"));
274 EXPECT_THAT(util::GetString16(test, 0), Eq(u"style"));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800275
Adam Lesinski060b53d2017-07-28 17:10:35 -0700276 const ResStringPool_span* span = test.styleAt(0);
277 ASSERT_THAT(span, NotNull());
278 EXPECT_THAT(util::GetString(test, span->name.index), Eq("b"));
279 EXPECT_THAT(util::GetString16(test, span->name.index), Eq(u"b"));
280 EXPECT_THAT(span->firstChar, Eq(0u));
281 EXPECT_THAT(span->lastChar, Eq(1u));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700282 span++;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800283
Adam Lesinski060b53d2017-07-28 17:10:35 -0700284 ASSERT_THAT(span->name.index, Ne(ResStringPool_span::END));
285 EXPECT_THAT(util::GetString(test, span->name.index), Eq("i"));
286 EXPECT_THAT(util::GetString16(test, span->name.index), Eq(u"i"));
287 EXPECT_THAT(span->firstChar, Eq(2u));
288 EXPECT_THAT(span->lastChar, Eq(3u));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700289 span++;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800290
Adam Lesinski060b53d2017-07-28 17:10:35 -0700291 EXPECT_THAT(span->name.index, Eq(ResStringPool_span::END));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700292 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800293}
294
Ryan Mitchell70414f22018-03-26 11:05:31 -0700295
296TEST(StringPoolTest, MaxEncodingLength) {
297 StdErrDiagnostics diag;
298 using namespace android; // For NO_ERROR on Windows.
299 ResStringPool test;
300
301 StringPool pool;
302 pool.MakeRef("aaaaaaaaaa");
303 BigBuffer buffers[2] = {BigBuffer(1024), BigBuffer(1024)};
304
305 // Make sure a UTF-8 string under the maximum length does not produce an error
306 EXPECT_THAT(StringPool::FlattenUtf8(&buffers[0], pool, &diag), Eq(true));
307 std::unique_ptr<uint8_t[]> data = util::Copy(buffers[0]);
308 test.setTo(data.get(), buffers[0].size());
309 EXPECT_THAT(util::GetString(test, 0), Eq("aaaaaaaaaa"));
310
311 // Make sure a UTF-16 string under the maximum length does not produce an error
312 EXPECT_THAT(StringPool::FlattenUtf16(&buffers[1], pool, &diag), Eq(true));
313 data = util::Copy(buffers[1]);
314 test.setTo(data.get(), buffers[1].size());
315 EXPECT_THAT(util::GetString16(test, 0), Eq(u"aaaaaaaaaa"));
316
317 StringPool pool2;
318 std::string longStr(50000, 'a');
319 pool2.MakeRef("this fits1");
320 pool2.MakeRef(longStr);
321 pool2.MakeRef("this fits2");
322 BigBuffer buffers2[2] = {BigBuffer(1024), BigBuffer(1024)};
323
324 // Make sure a string that exceeds the maximum length of UTF-8 produces an
325 // error and writes a shorter error string instead
326 EXPECT_THAT(StringPool::FlattenUtf8(&buffers2[0], pool2, &diag), Eq(false));
327 data = util::Copy(buffers2[0]);
328 test.setTo(data.get(), buffers2[0].size());
329 EXPECT_THAT(util::GetString(test, 0), "this fits1");
330 EXPECT_THAT(util::GetString(test, 1), "STRING_TOO_LARGE");
331 EXPECT_THAT(util::GetString(test, 2), "this fits2");
332
333 // Make sure a string that a string that exceeds the maximum length of UTF-8
334 // but not UTF-16 does not error for UTF-16
335 StringPool pool3;
336 std::u16string longStr16(50000, 'a');
337 pool3.MakeRef(longStr);
338 EXPECT_THAT(StringPool::FlattenUtf16(&buffers2[1], pool3, &diag), Eq(true));
339 data = util::Copy(buffers2[1]);
340 test.setTo(data.get(), buffers2[1].size());
341 EXPECT_THAT(util::GetString16(test, 0), Eq(longStr16));
342}
343
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700344} // namespace aapt