entry_name_utils_test.cc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #include "entry_name_utils-inl.h"
  17. #include <gtest/gtest.h>
  18. TEST(entry_name_utils, NullChars) {
  19. // 'A', 'R', '\0', 'S', 'E'
  20. const uint8_t zeroes[] = {0x41, 0x52, 0x00, 0x53, 0x45};
  21. ASSERT_FALSE(IsValidEntryName(zeroes, sizeof(zeroes)));
  22. const uint8_t zeroes_continuation_chars[] = {0xc2, 0xa1, 0xc2, 0x00};
  23. ASSERT_FALSE(IsValidEntryName(zeroes_continuation_chars, sizeof(zeroes_continuation_chars)));
  24. }
  25. TEST(entry_name_utils, InvalidSequence) {
  26. // 0xfe is an invalid start byte
  27. const uint8_t invalid[] = {0x41, 0xfe};
  28. ASSERT_FALSE(IsValidEntryName(invalid, sizeof(invalid)));
  29. // 0x91 is an invalid start byte (it's a valid continuation byte).
  30. const uint8_t invalid2[] = {0x41, 0x91};
  31. ASSERT_FALSE(IsValidEntryName(invalid2, sizeof(invalid2)));
  32. }
  33. TEST(entry_name_utils, TruncatedContinuation) {
  34. // Malayalam script with truncated bytes. There should be 2 bytes
  35. // after 0xe0
  36. const uint8_t truncated[] = {0xe0, 0xb4, 0x85, 0xe0, 0xb4};
  37. ASSERT_FALSE(IsValidEntryName(truncated, sizeof(truncated)));
  38. // 0xc2 is the start of a 2 byte sequence that we've subsequently
  39. // dropped.
  40. const uint8_t truncated2[] = {0xc2, 0xc2, 0xa1};
  41. ASSERT_FALSE(IsValidEntryName(truncated2, sizeof(truncated2)));
  42. }
  43. TEST(entry_name_utils, BadContinuation) {
  44. // 0x41 is an invalid continuation char, since it's MSBs
  45. // aren't "10..." (are 01).
  46. const uint8_t bad[] = {0xc2, 0xa1, 0xc2, 0x41};
  47. ASSERT_FALSE(IsValidEntryName(bad, sizeof(bad)));
  48. // 0x41 is an invalid continuation char, since it's MSBs
  49. // aren't "10..." (are 11).
  50. const uint8_t bad2[] = {0xc2, 0xa1, 0xc2, 0xfe};
  51. ASSERT_FALSE(IsValidEntryName(bad2, sizeof(bad2)));
  52. }