/* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "PhonebookIndex.h" #include #include #include #include using namespace android; class TestExecutor { public: TestExecutor() : m_total_count(0), m_success_count(0), m_success(true) {} bool DoAllTests(); private: void DoOneTest(void (TestExecutor::*test)()); void testGetIndex(const char *src, const char *locale, int32_t expected_len, UChar *expected_value); void testEnglish(); // Note: When adding a test, do not forget to add it to DoOneTest(). int m_total_count; int m_success_count; bool m_success; }; bool TestExecutor::DoAllTests() { DoOneTest(&TestExecutor::testEnglish); printf("Test total: %d\nSuccess: %d\nFailure: %d\n", m_total_count, m_success_count, m_total_count - m_success_count); bool success = m_total_count == m_success_count; printf("\n%s\n", success ? "Success" : "Failure"); return success; } void TestExecutor::DoOneTest(void (TestExecutor::*test)()) { m_success = true; (this->*test)(); ++m_total_count; m_success_count += m_success ? 1 : 0; } #define BUFFER_SIZE 10 static void printUTF8Str(const char *utf8_str) { printf("%s (", utf8_str); for(; *utf8_str != '\0'; ++utf8_str) { printf("\\x%02hhX", *utf8_str); } printf(")"); } static void printUChars(const UChar *uc_str, int32_t len) { std::string utf8_str; UnicodeString(uc_str, len).toUTF8String(utf8_str); printf("%s (", utf8_str.c_str()); for(int i=0; i