Narayan Kamath | 044bc8e | 2014-12-03 18:22:53 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 21 | TEST(entry_name_utils, NullChars) { |
| 22 | // 'A', 'R', '\0', 'S', 'E' |
Jiyong Park | cd997e6 | 2017-06-30 17:23:33 +0900 | [diff] [blame] | 23 | const uint8_t zeroes[] = {0x41, 0x52, 0x00, 0x53, 0x45}; |
Narayan Kamath | 044bc8e | 2014-12-03 18:22:53 +0000 | [diff] [blame] | 24 | ASSERT_FALSE(IsValidEntryName(zeroes, sizeof(zeroes))); |
| 25 | |
Jiyong Park | cd997e6 | 2017-06-30 17:23:33 +0900 | [diff] [blame] | 26 | const uint8_t zeroes_continuation_chars[] = {0xc2, 0xa1, 0xc2, 0x00}; |
| 27 | ASSERT_FALSE(IsValidEntryName(zeroes_continuation_chars, sizeof(zeroes_continuation_chars))); |
Narayan Kamath | 044bc8e | 2014-12-03 18:22:53 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | TEST(entry_name_utils, InvalidSequence) { |
| 31 | // 0xfe is an invalid start byte |
Jiyong Park | cd997e6 | 2017-06-30 17:23:33 +0900 | [diff] [blame] | 32 | const uint8_t invalid[] = {0x41, 0xfe}; |
Narayan Kamath | 044bc8e | 2014-12-03 18:22:53 +0000 | [diff] [blame] | 33 | ASSERT_FALSE(IsValidEntryName(invalid, sizeof(invalid))); |
| 34 | |
| 35 | // 0x91 is an invalid start byte (it's a valid continuation byte). |
Jiyong Park | cd997e6 | 2017-06-30 17:23:33 +0900 | [diff] [blame] | 36 | const uint8_t invalid2[] = {0x41, 0x91}; |
Narayan Kamath | 044bc8e | 2014-12-03 18:22:53 +0000 | [diff] [blame] | 37 | ASSERT_FALSE(IsValidEntryName(invalid2, sizeof(invalid2))); |
| 38 | } |
| 39 | |
| 40 | TEST(entry_name_utils, TruncatedContinuation) { |
| 41 | // Malayalam script with truncated bytes. There should be 2 bytes |
| 42 | // after 0xe0 |
Jiyong Park | cd997e6 | 2017-06-30 17:23:33 +0900 | [diff] [blame] | 43 | const uint8_t truncated[] = {0xe0, 0xb4, 0x85, 0xe0, 0xb4}; |
Narayan Kamath | 044bc8e | 2014-12-03 18:22:53 +0000 | [diff] [blame] | 44 | ASSERT_FALSE(IsValidEntryName(truncated, sizeof(truncated))); |
| 45 | |
| 46 | // 0xc2 is the start of a 2 byte sequence that we've subsequently |
| 47 | // dropped. |
Jiyong Park | cd997e6 | 2017-06-30 17:23:33 +0900 | [diff] [blame] | 48 | const uint8_t truncated2[] = {0xc2, 0xc2, 0xa1}; |
Narayan Kamath | 044bc8e | 2014-12-03 18:22:53 +0000 | [diff] [blame] | 49 | ASSERT_FALSE(IsValidEntryName(truncated2, sizeof(truncated2))); |
| 50 | } |
| 51 | |
| 52 | TEST(entry_name_utils, BadContinuation) { |
| 53 | // 0x41 is an invalid continuation char, since it's MSBs |
| 54 | // aren't "10..." (are 01). |
Jiyong Park | cd997e6 | 2017-06-30 17:23:33 +0900 | [diff] [blame] | 55 | const uint8_t bad[] = {0xc2, 0xa1, 0xc2, 0x41}; |
Narayan Kamath | 044bc8e | 2014-12-03 18:22:53 +0000 | [diff] [blame] | 56 | 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 Park | cd997e6 | 2017-06-30 17:23:33 +0900 | [diff] [blame] | 60 | const uint8_t bad2[] = {0xc2, 0xa1, 0xc2, 0xfe}; |
Narayan Kamath | 044bc8e | 2014-12-03 18:22:53 +0000 | [diff] [blame] | 61 | ASSERT_FALSE(IsValidEntryName(bad2, sizeof(bad2))); |
| 62 | } |