| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009, Google Inc. | |
| 2 // All rights reserved. | |
| 3 // | |
| 4 // Redistribution and use in source and binary forms, with or without | |
| 5 // modification, are permitted provided that the following conditions are | |
| 6 // met: | |
| 7 // | |
| 8 // * Redistributions of source code must retain the above copyright | |
| 9 // notice, this list of conditions and the following disclaimer. | |
| 10 // * Redistributions in binary form must reproduce the above | |
| 11 // copyright notice, this list of conditions and the following disclaimer | |
| 12 // in the documentation and/or other materials provided with the | |
| 13 // distribution. | |
| 14 // * Neither the name of Google Inc. nor the names of its | |
| 15 // contributors may be used to endorse or promote products derived from | |
| 16 // this software without specific prior written permission. | |
| 17 // | |
| 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 | |
| 30 #include "breakpad/linux/linux_libc_support.h" | |
| 31 #include "testing/gtest/include/gtest/gtest.h" | |
| 32 | |
| 33 namespace { | |
| 34 typedef testing::Test LinuxLibcSupportTest; | |
| 35 } | |
| 36 | |
| 37 TEST(LinuxLibcSupportTest, strlen) { | |
| 38 static const char* test_data[] = { "", "a", "aa", "aaa", "aabc", NULL }; | |
| 39 for (unsigned i = 0; ; ++i) { | |
| 40 if (!test_data[i]) | |
| 41 break; | |
| 42 ASSERT_EQ(strlen(test_data[i]), my_strlen(test_data[i])); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 TEST(LinuxLibcSupportTest, strcmp) { | |
| 47 static const char* test_data[] = { | |
| 48 "", "", | |
| 49 "a", "", | |
| 50 "", "a", | |
| 51 "a", "b", | |
| 52 "a", "a", | |
| 53 "ab", "aa", | |
| 54 "abc", "ab", | |
| 55 "abc", "abc", | |
| 56 NULL, | |
| 57 }; | |
| 58 | |
| 59 for (unsigned i = 0; ; ++i) { | |
| 60 if (!test_data[i*2]) | |
| 61 break; | |
| 62 ASSERT_EQ(my_strcmp(test_data[i*2], test_data[i*2 + 1]), | |
| 63 strcmp(test_data[i*2], test_data[i*2 + 1])); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 TEST(LinuxLibcSupportTest, strtoui) { | |
| 68 int result; | |
| 69 | |
| 70 ASSERT_FALSE(my_strtoui(&result, "")); | |
| 71 ASSERT_FALSE(my_strtoui(&result, "-1")); | |
| 72 ASSERT_FALSE(my_strtoui(&result, "-")); | |
| 73 ASSERT_FALSE(my_strtoui(&result, "a")); | |
| 74 ASSERT_FALSE(my_strtoui(&result, "23472893472938472987987398472398")); | |
| 75 | |
| 76 ASSERT_TRUE(my_strtoui(&result, "0")); | |
| 77 ASSERT_EQ(result, 0); | |
| 78 ASSERT_TRUE(my_strtoui(&result, "1")); | |
| 79 ASSERT_EQ(result, 1); | |
| 80 ASSERT_TRUE(my_strtoui(&result, "12")); | |
| 81 ASSERT_EQ(result, 12); | |
| 82 ASSERT_TRUE(my_strtoui(&result, "123")); | |
| 83 ASSERT_EQ(result, 123); | |
| 84 ASSERT_TRUE(my_strtoui(&result, "0123")); | |
| 85 ASSERT_EQ(result, 123); | |
| 86 } | |
| 87 | |
| 88 TEST(LinuxLibcSupportTest, int_len) { | |
| 89 ASSERT_EQ(my_int_len(0), 1); | |
| 90 ASSERT_EQ(my_int_len(2), 1); | |
| 91 ASSERT_EQ(my_int_len(5), 1); | |
| 92 ASSERT_EQ(my_int_len(9), 1); | |
| 93 ASSERT_EQ(my_int_len(10), 2); | |
| 94 ASSERT_EQ(my_int_len(99), 2); | |
| 95 ASSERT_EQ(my_int_len(100), 3); | |
| 96 ASSERT_EQ(my_int_len(101), 3); | |
| 97 ASSERT_EQ(my_int_len(1000), 4); | |
| 98 } | |
| 99 | |
| 100 TEST(LinuxLibcSupportTest, itos) { | |
| 101 char buf[10]; | |
| 102 | |
| 103 my_itos(buf, 0, 1); | |
| 104 ASSERT_EQ(0, memcmp(buf, "0", 1)); | |
| 105 | |
| 106 my_itos(buf, 1, 1); | |
| 107 ASSERT_EQ(0, memcmp(buf, "1", 1)); | |
| 108 | |
| 109 my_itos(buf, 10, 2); | |
| 110 ASSERT_EQ(0, memcmp(buf, "10", 2)); | |
| 111 | |
| 112 my_itos(buf, 63, 2); | |
| 113 ASSERT_EQ(0, memcmp(buf, "63", 2)); | |
| 114 | |
| 115 my_itos(buf, 101, 3); | |
| 116 ASSERT_EQ(0, memcmp(buf, "101", 2)); | |
| 117 } | |
| 118 | |
| 119 TEST(LinuxLibcSupportTest, strchr) { | |
| 120 ASSERT_EQ(NULL, my_strchr("abc", 'd')); | |
| 121 ASSERT_EQ(NULL, my_strchr("", 'd')); | |
| 122 ASSERT_EQ(NULL, my_strchr("efghi", 'd')); | |
| 123 | |
| 124 ASSERT_TRUE(my_strchr("a", 'a')); | |
| 125 ASSERT_TRUE(my_strchr("abc", 'a')); | |
| 126 ASSERT_TRUE(my_strchr("bcda", 'a')); | |
| 127 ASSERT_TRUE(my_strchr("sdfasdf", 'a')); | |
| 128 } | |
| 129 | |
| 130 TEST(LinuxLibcSupportTest, read_hex_ptr) { | |
| 131 uintptr_t result; | |
| 132 const char* last; | |
| 133 | |
| 134 last = my_read_hex_ptr(&result, ""); | |
| 135 ASSERT_EQ(result, 0); | |
| 136 ASSERT_EQ(*last, 0); | |
| 137 | |
| 138 last = my_read_hex_ptr(&result, "0"); | |
| 139 ASSERT_EQ(result, 0); | |
| 140 ASSERT_EQ(*last, 0); | |
| 141 | |
| 142 last = my_read_hex_ptr(&result, "0123"); | |
| 143 ASSERT_EQ(result, 0x123); | |
| 144 ASSERT_EQ(*last, 0); | |
| 145 | |
| 146 last = my_read_hex_ptr(&result, "0123a"); | |
| 147 ASSERT_EQ(result, 0x123a); | |
| 148 ASSERT_EQ(*last, 0); | |
| 149 | |
| 150 last = my_read_hex_ptr(&result, "0123a-"); | |
| 151 ASSERT_EQ(result, 0x123a); | |
| 152 ASSERT_EQ(*last, '-'); | |
| 153 } | |
| OLD | NEW |