blob: d83d8540cc2cc74032827a95e9c856725814414f [file] [log] [blame]
Narayan Kamath044bc8e2014-12-03 18:22:53 +00001/*
2 * Copyright (C) 2014 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 "entry_name_utils-inl.h"
18
19#include <gtest/gtest.h>
20
21TEST(entry_name_utils, NullChars) {
22 // 'A', 'R', '\0', 'S', 'E'
Jiyong Parkcd997e62017-06-30 17:23:33 +090023 const uint8_t zeroes[] = {0x41, 0x52, 0x00, 0x53, 0x45};
Narayan Kamath044bc8e2014-12-03 18:22:53 +000024 ASSERT_FALSE(IsValidEntryName(zeroes, sizeof(zeroes)));
25
Jiyong Parkcd997e62017-06-30 17:23:33 +090026 const uint8_t zeroes_continuation_chars[] = {0xc2, 0xa1, 0xc2, 0x00};
27 ASSERT_FALSE(IsValidEntryName(zeroes_continuation_chars, sizeof(zeroes_continuation_chars)));
Narayan Kamath044bc8e2014-12-03 18:22:53 +000028}
29
30TEST(entry_name_utils, InvalidSequence) {
31 // 0xfe is an invalid start byte
Jiyong Parkcd997e62017-06-30 17:23:33 +090032 const uint8_t invalid[] = {0x41, 0xfe};
Narayan Kamath044bc8e2014-12-03 18:22:53 +000033 ASSERT_FALSE(IsValidEntryName(invalid, sizeof(invalid)));
34
35 // 0x91 is an invalid start byte (it's a valid continuation byte).
Jiyong Parkcd997e62017-06-30 17:23:33 +090036 const uint8_t invalid2[] = {0x41, 0x91};
Narayan Kamath044bc8e2014-12-03 18:22:53 +000037 ASSERT_FALSE(IsValidEntryName(invalid2, sizeof(invalid2)));
38}
39
40TEST(entry_name_utils, TruncatedContinuation) {
41 // Malayalam script with truncated bytes. There should be 2 bytes
42 // after 0xe0
Jiyong Parkcd997e62017-06-30 17:23:33 +090043 const uint8_t truncated[] = {0xe0, 0xb4, 0x85, 0xe0, 0xb4};
Narayan Kamath044bc8e2014-12-03 18:22:53 +000044 ASSERT_FALSE(IsValidEntryName(truncated, sizeof(truncated)));
45
46 // 0xc2 is the start of a 2 byte sequence that we've subsequently
47 // dropped.
Jiyong Parkcd997e62017-06-30 17:23:33 +090048 const uint8_t truncated2[] = {0xc2, 0xc2, 0xa1};
Narayan Kamath044bc8e2014-12-03 18:22:53 +000049 ASSERT_FALSE(IsValidEntryName(truncated2, sizeof(truncated2)));
50}
51
52TEST(entry_name_utils, BadContinuation) {
53 // 0x41 is an invalid continuation char, since it's MSBs
54 // aren't "10..." (are 01).
Jiyong Parkcd997e62017-06-30 17:23:33 +090055 const uint8_t bad[] = {0xc2, 0xa1, 0xc2, 0x41};
Narayan Kamath044bc8e2014-12-03 18:22:53 +000056 ASSERT_FALSE(IsValidEntryName(bad, sizeof(bad)));
57
58 // 0x41 is an invalid continuation char, since it's MSBs
59 // aren't "10..." (are 11).
Jiyong Parkcd997e62017-06-30 17:23:33 +090060 const uint8_t bad2[] = {0xc2, 0xa1, 0xc2, 0xfe};
Narayan Kamath044bc8e2014-12-03 18:22:53 +000061 ASSERT_FALSE(IsValidEntryName(bad2, sizeof(bad2)));
62}