Open Chinese Convert
1.0.3
A project for conversion between Traditional and Simplified Chinese
|
00001 /* 00002 * Open Chinese Convert 00003 * 00004 * Copyright 2010-2014 BYVoid <byvoid@byvoid.com> 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 00019 #pragma once 00020 00021 #include <string> 00022 #include "gtest/gtest.h" 00023 00024 namespace opencc { 00025 00026 using std::string; 00027 00028 #ifdef _MSC_VER 00029 #define __func__ __FUNCTION__ 00030 #endif // ifdef _MSC_VER 00031 00032 #if defined(_MSC_VER) && _MSC_VER > 1310 00033 // Visual C++ 2005 and later require the source files in UTF-8, and all strings 00034 // to be encoded as wchar_t otherwise the strings will be converted into the 00035 // local multibyte encoding and cause errors. To use a wchar_t as UTF-8, these 00036 // strings then need to be convert back to UTF-8. This function is just a rough 00037 // example of how to do this. 00038 #include <Windows.h> 00039 #define utf8(str) ConvertToUTF8(L##str) 00040 string ConvertToUTF8(const wchar_t* pStr) { 00041 static char szBuf[1024]; 00042 WideCharToMultiByte(CP_UTF8, 0, pStr, -1, szBuf, sizeof(szBuf), NULL, NULL); 00043 return szBuf; 00044 } 00045 00046 #else // if defined(_MSC_VER) && _MSC_VER > 1310 00047 // Visual C++ 2003 and gcc will use the string literals as is, so the files 00048 // should be saved as UTF-8. gcc requires the files to not have a UTF-8 BOM. 00049 #define utf8(str) string(str) 00050 #endif // if defined(_MSC_VER) && _MSC_VER > 1310 00051 00052 #define EXPECT_VECTOR_EQ(expected, actual) \ 00053 { \ 00054 const auto& a1 = (expected); \ 00055 const auto& a2 = (actual); \ 00056 EXPECT_EQ(a1.size(), a2.size()); \ 00057 for (size_t i = 0; i < a1.size(); i++) { \ 00058 EXPECT_EQ(a1[i], a2[i]) << "Where i = " << i; \ 00059 } \ 00060 } 00061 00062 } // namespace opencc