mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
code for cpinfo
This commit is contained in:
+2
-1
@@ -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
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#include "getcpinfo.h"
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,40 @@
|
||||
#include <gtest/gtest.h>
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user