|
| 1 | +/* Copyright (C) 2003-2015 LiveCode Ltd. |
| 2 | + |
| 3 | + This file is part of LiveCode. |
| 4 | + |
| 5 | + LiveCode is free software; you can redistribute it and/or modify it under |
| 6 | + the terms of the GNU General Public License v3 as published by the Free |
| 7 | + Software Foundation. |
| 8 | + |
| 9 | + LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 | + WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + for more details. |
| 13 | + |
| 14 | + You should have received a copy of the GNU General Public License |
| 15 | + along with LiveCode. If not see <http://www.gnu.org/licenses/>. */ |
| 16 | + |
| 17 | +#include "gtest/gtest.h" |
| 18 | + |
| 19 | +#include "foundation.h" |
| 20 | +#include "foundation-auto.h" |
| 21 | + |
| 22 | +TEST(name, index_equal_string) |
| 23 | +{ |
| 24 | + static index_t s_test_indicies[] = |
| 25 | + { |
| 26 | + INT32_MIN + 32, |
| 27 | + INT16_MIN, |
| 28 | + INT8_MIN, |
| 29 | + 0, |
| 30 | + INT8_MAX, |
| 31 | + INT16_MAX, |
| 32 | + INT32_MAX - 32, |
| 33 | + }; |
| 34 | + for(size_t i = 0; i < sizeof(s_test_indicies) / sizeof(s_test_indicies[0]); i++) |
| 35 | + { |
| 36 | + for(int j = -32; j <= 32; j++) |
| 37 | + { |
| 38 | + int64_t t_full_index = s_test_indicies[i] + j; |
| 39 | + index_t t_index = (index_t)t_full_index; |
| 40 | + char_t t_index_str[32]; |
| 41 | + sprintf((char *)t_index_str, "%lld", t_full_index); |
| 42 | + |
| 43 | + // fprintf(stderr, "%lld, %d\n", t_full_index, t_index); |
| 44 | + |
| 45 | + MCNewAutoNameRef t_index_name, t_string_name; |
| 46 | + ASSERT_TRUE(MCNameCreateWithIndex(t_index, &t_index_name)); |
| 47 | + ASSERT_TRUE(MCNameCreateWithNativeChars(t_index_str, strlen((char *)t_index_str), &t_string_name)); |
| 48 | + // fprintf(stderr, "%s, %s\n", MCStringGetCString(MCNameGetString(*t_index_name)), MCStringGetCString(MCNameGetString(*t_string_name))); |
| 49 | + ASSERT_EQ(*t_index_name, *t_string_name); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +TEST(name, distinct_string) |
| 55 | +{ |
| 56 | + static constexpr const char *s_test_names[] = |
| 57 | + { |
| 58 | + "foo", |
| 59 | + "bar", |
| 60 | + "baz" |
| 61 | + "foobar", |
| 62 | + "foobaz", |
| 63 | + "foobarbaz", |
| 64 | + }; |
| 65 | + static constexpr size_t s_test_name_count = sizeof(s_test_names) / sizeof(s_test_names[0]); |
| 66 | + |
| 67 | + MCNewAutoNameRef t_names[s_test_name_count]; |
| 68 | + for(size_t i = 0; i < s_test_name_count; i++) |
| 69 | + { |
| 70 | + ASSERT_TRUE(MCNameCreateWithNativeChars((const char_t *)s_test_names[i], strlen(s_test_names[i]), &t_names[i])); |
| 71 | + for(size_t j = 0; j < i; j++) |
| 72 | + ASSERT_NE(*t_names[i], *t_names[j]); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +TEST(name, equal_string) |
| 77 | +{ |
| 78 | + static constexpr const char *s_test_names[] = |
| 79 | + { |
| 80 | + "foo", |
| 81 | + "foo", |
| 82 | + "baz", |
| 83 | + "baz", |
| 84 | + "foobaz", |
| 85 | + "foobaz", |
| 86 | + }; |
| 87 | + static constexpr size_t s_test_name_count = sizeof(s_test_names) / sizeof(s_test_names[0]); |
| 88 | + |
| 89 | + MCNewAutoNameRef t_names[s_test_name_count]; |
| 90 | + for(size_t i = 0; i < s_test_name_count; i++) |
| 91 | + { |
| 92 | + ASSERT_TRUE(MCNameCreateWithNativeChars((const char_t *)s_test_names[i], strlen(s_test_names[i]), &t_names[i])); |
| 93 | + } |
| 94 | + for(size_t i = 0; i < s_test_name_count / 2; i++) |
| 95 | + { |
| 96 | + ASSERT_EQ(*t_names[i * 2], *t_names[i * 2 + 1]); |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +TEST(name, equiv_string) |
| 101 | +{ |
| 102 | + static constexpr const char *s_test_names[] = |
| 103 | + { |
| 104 | + "foo", |
| 105 | + "FoO", |
| 106 | + "baz", |
| 107 | + "baZ", |
| 108 | + "fooBaz", |
| 109 | + "Foobaz", |
| 110 | + }; |
| 111 | + static constexpr size_t s_test_name_count = sizeof(s_test_names) / sizeof(s_test_names[0]); |
| 112 | + |
| 113 | + MCNewAutoNameRef t_names[s_test_name_count]; |
| 114 | + for(size_t i = 0; i < s_test_name_count; i++) |
| 115 | + { |
| 116 | + ASSERT_TRUE(MCNameCreateWithNativeChars((const char_t *)s_test_names[i], strlen(s_test_names[i]), &t_names[i])); |
| 117 | + } |
| 118 | + for(size_t i = 0; i < s_test_name_count / 2; i++) |
| 119 | + { |
| 120 | + fprintf(stderr, "%s, %s\n", MCStringGetCString(MCNameGetString(*t_names[i * 2])), MCStringGetCString(MCNameGetString(*t_names[i * 2 + 1]))); |
| 121 | + ASSERT_TRUE(MCNameIsEqualToCaseless(*t_names[i * 2], *t_names[i * 2 + 1])); |
| 122 | + } |
| 123 | +} |
0 commit comments