From ac95206250ac27740a9b91fdde8d6afe682bdb57 Mon Sep 17 00:00:00 2001 From: Aaron Katz Date: Fri, 20 Mar 2015 10:07:06 -0700 Subject: [PATCH] code for cpinfo --- src/CMakeLists.txt | 3 ++- src/impl/getcpinfo.cpp | 27 ++++++++++++++++++++++++ src/impl/getcpinfo.h | 22 ++++++++++++++++++++ src/tests/test-getcpinfo.cpp | 40 ++++++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/impl/getcpinfo.cpp create mode 100644 src/impl/getcpinfo.h create mode 100644 src/tests/test-getcpinfo.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4355f98d04..018b963fcd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,7 +6,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") #include gtest include_directories(../ext-src/gtest/fused-src impl) -set(SOURCE_FILES main.cpp tests/test-getcurrentprocessid.cpp impl/getcurrentprocessorid.cpp ../ext-src/gtest/fused-src/gtest/gtest-all.cc) +set(SOURCE_FILES main.cpp tests/test-getcurrentprocessid.cpp impl/getcurrentprocessorid.cpp tests/test-getcpinfo.cpp impl/getcpinfo.cpp +../ext-src/gtest/fused-src/gtest/gtest-all.cc) add_executable(monad_native ${SOURCE_FILES}) # add pthread diff --git a/src/impl/getcpinfo.cpp b/src/impl/getcpinfo.cpp new file mode 100644 index 0000000000..1392f79709 --- /dev/null +++ b/src/impl/getcpinfo.cpp @@ -0,0 +1,27 @@ +#include "getcpinfo.h" +#include + +bool GetCPInfo(unsigned int codepage, LPCPINFO cpinfo) +{ + switch(codepage) + { + case 65000: + cpinfo->DefaultChar[0]= '?'; + cpinfo->DefaultChar[1]= '0'; + cpinfo->LeadByte[0] = cpinfo->LeadByte[1] = '0'; + cpinfo->MaxCharSize = 5; + return true; + break; + case 65001: + cpinfo->DefaultChar[0]= '?'; + cpinfo->DefaultChar[1]= '0'; + cpinfo->LeadByte[0] = cpinfo->LeadByte[1] = '0'; + cpinfo->MaxCharSize = 4; + return true; + break; + default: + return false; + } + +} + diff --git a/src/impl/getcpinfo.h b/src/impl/getcpinfo.h new file mode 100644 index 0000000000..2e11196bde --- /dev/null +++ b/src/impl/getcpinfo.h @@ -0,0 +1,22 @@ +#pragma once + +#include "pal.h" + +PAL_BEGIN_EXTERNC + + + const int MAX_DEFAULTCHAR = 2; + + const int MAX_LEADBYTES = 12; + + +typedef struct _cpinfo { + unsigned int MaxCharSize; + char DefaultChar[MAX_DEFAULTCHAR]; + char LeadByte[MAX_LEADBYTES]; +} CPINFO, *LPCPINFO; + + +bool GetCPInfo(unsigned int codepage, LPCPINFO cpinfo); + +PAL_END_EXTERNC diff --git a/src/tests/test-getcpinfo.cpp b/src/tests/test-getcpinfo.cpp new file mode 100644 index 0000000000..2a23121ecc --- /dev/null +++ b/src/tests/test-getcpinfo.cpp @@ -0,0 +1,40 @@ +#include +#include "getcpinfo.h" + +// This is a very simple test case to show how tests can be written +TEST(GetCPInfo,utf8) +{ + + LPCPINFO cpinfo = new CPINFO(); + bool utf8 = GetCPInfo(65001, cpinfo); + + + // first make sure that on this platform those types are of the same size + ASSERT_TRUE(utf8 == 1); + + // now compare the actual values + ASSERT_EQ(cpinfo->DefaultChar[0],'?'); + ASSERT_EQ(cpinfo->DefaultChar[1],'0'); + ASSERT_EQ(cpinfo->LeadByte[0] ,'0'); + ASSERT_EQ(cpinfo->LeadByte[1] ,'0'); + ASSERT_EQ(cpinfo->MaxCharSize ,4); + +} + + +TEST(GetCPInfo,utf7) +{ + LPCPINFO cpinfo = new CPINFO(); + bool utf7 = GetCPInfo(65000, cpinfo); + + + // first make sure that on this platform those types are of the same size + ASSERT_TRUE(utf7 == 1); + + // now compare the actual values + ASSERT_EQ(cpinfo->DefaultChar[0],'?'); + ASSERT_EQ(cpinfo->DefaultChar[1],'0'); + ASSERT_EQ(cpinfo->LeadByte[0] ,'0'); + ASSERT_EQ(cpinfo->LeadByte[1] ,'0'); + ASSERT_EQ(cpinfo->MaxCharSize ,5); +} \ No newline at end of file