mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 16:45:50 +00:00
[ATL][ATL_APITEST] Add GetEnvironmentVariable to CString. CORE-12581
svn path=/trunk/; revision=73465
This commit is contained in:
parent
71d5b09683
commit
f1167250a0
3 changed files with 83 additions and 13 deletions
|
@ -83,6 +83,14 @@ public:
|
|||
::CharLowerBuffW(pszSource, nSrcLength);
|
||||
}
|
||||
|
||||
static DWORD GetEnvironmentVariable(
|
||||
_In_z_ LPCWSTR pszVar,
|
||||
_Out_writes_opt_(nBufLength) LPWSTR pszBuf,
|
||||
_In_opt_ int nBufLength)
|
||||
{
|
||||
return ::GetEnvironmentVariableW(pszVar, pszBuf, nBufLength);
|
||||
}
|
||||
|
||||
static void __cdecl MakeUpper(
|
||||
_Out_writes_(nSrcLength) LPWSTR pszSource,
|
||||
_In_ int nSrcLength)
|
||||
|
@ -201,6 +209,14 @@ public:
|
|||
::CharLowerBuffA(pszSource, nSrcLength);
|
||||
}
|
||||
|
||||
static DWORD GetEnvironmentVariable(
|
||||
_In_z_ LPCSTR pszVar,
|
||||
_Out_writes_opt_(nBufLength) LPSTR pszBuf,
|
||||
_In_opt_ int nBufLength)
|
||||
{
|
||||
return ::GetEnvironmentVariableA(pszVar, pszBuf, nBufLength);
|
||||
}
|
||||
|
||||
static void __cdecl MakeUpper(
|
||||
_Out_writes_(nSrcLength) LPSTR pszSource,
|
||||
_In_ int nSrcLength)
|
||||
|
@ -452,6 +468,22 @@ public:
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL GetEnvironmentVariable(_In_z_ PCXSTR pszVar)
|
||||
{
|
||||
int nLength = StringTraits::GetEnvironmentVariable(pszVar, NULL, 0);
|
||||
|
||||
if (nLength > 0)
|
||||
{
|
||||
PXSTR pszBuffer = CThisSimpleString::GetBuffer(nLength);
|
||||
StringTraits::GetEnvironmentVariable(pszVar, pszBuffer, nLength);
|
||||
CThisSimpleString::ReleaseBuffer();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CThisSimpleString::Empty();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CStringT& MakeLower()
|
||||
{
|
||||
int nLength = CThisSimpleString::GetLength();
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* PROGRAMMER: Mark Jansen
|
||||
*/
|
||||
|
||||
#include <apitest.h>
|
||||
#include <atlstr.h>
|
||||
#include <apitest.h>
|
||||
|
||||
|
||||
struct traits_test
|
||||
|
@ -119,12 +119,13 @@ static void test_basetypes()
|
|||
#undef ok
|
||||
#undef _T
|
||||
|
||||
#define TEST_NAMEX(name) void test_##name##W()
|
||||
#define CStringX CStringW
|
||||
#define _X(x) L ## x
|
||||
#define XCHAR WCHAR
|
||||
#define dbgstrx(x) wine_dbgstr_w(x)
|
||||
#define ok ok_("CStringW:\n" __FILE__, __LINE__)
|
||||
#define TEST_NAMEX(name) void test_##name##W()
|
||||
#define CStringX CStringW
|
||||
#define _X(x) L ## x
|
||||
#define XCHAR WCHAR
|
||||
#define dbgstrx(x) wine_dbgstr_w(x)
|
||||
#define ok ok_("CStringW:\n" __FILE__, __LINE__)
|
||||
#define GetWindowsDirectoryX GetWindowsDirectoryW
|
||||
#include "CString.inl"
|
||||
|
||||
|
||||
|
@ -134,13 +135,15 @@ static void test_basetypes()
|
|||
#undef XCHAR
|
||||
#undef dbgstrx
|
||||
#undef ok
|
||||
#undef GetWindowsDirectoryX
|
||||
|
||||
#define TEST_NAMEX(name) void test_##name##A()
|
||||
#define CStringX CStringA
|
||||
#define _X(x) x
|
||||
#define XCHAR CHAR
|
||||
#define dbgstrx(x) (const char*)x
|
||||
#define ok ok_("CStringA:\n" __FILE__, __LINE__)
|
||||
#define TEST_NAMEX(name) void test_##name##A()
|
||||
#define CStringX CStringA
|
||||
#define _X(x) x
|
||||
#define XCHAR CHAR
|
||||
#define dbgstrx(x) (const char*)x
|
||||
#define ok ok_("CStringA:\n" __FILE__, __LINE__)
|
||||
#define GetWindowsDirectoryX GetWindowsDirectoryA
|
||||
#include "CString.inl"
|
||||
|
||||
|
||||
|
@ -173,4 +176,7 @@ START_TEST(CString)
|
|||
|
||||
test_trimW();
|
||||
test_trimA();
|
||||
|
||||
test_envW();
|
||||
test_envA();
|
||||
}
|
||||
|
|
|
@ -356,3 +356,35 @@ TEST_NAMEX(trim)
|
|||
ok(str2 == _X(""), "Expected str2 to be '', was: %s\n", dbgstrx(str2));
|
||||
ok(str2.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", str2.GetLength());
|
||||
}
|
||||
|
||||
TEST_NAMEX(env)
|
||||
{
|
||||
CStringX test;
|
||||
BOOL ret;
|
||||
ok(test.IsEmpty() == true, "Expected test to be empty\n");
|
||||
ok(test.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", test.GetLength());
|
||||
ok(test.GetAllocLength() == 0, "Expected GetAllocLength() to be 0, was: %i\n", test.GetAllocLength());
|
||||
|
||||
XCHAR buf[512];
|
||||
GetWindowsDirectoryX(buf, _countof(buf));
|
||||
|
||||
ret = test.GetEnvironmentVariable(_X("SystemDrive"));
|
||||
ok(!!ret, "Expected %%SystemDrive%% to exist\n");
|
||||
ok(test.IsEmpty() == false, "Expected test to have a valid result\n");
|
||||
ok(test.GetLength() == 2, "Expected GetLength() to be 2, was: %i\n", test.GetLength());
|
||||
if (test.GetLength() == 2)
|
||||
{
|
||||
ok(test[0] == buf[0], "Expected test[0] to equal buf[0], was: %c, %c\n", test[0], buf[0]);
|
||||
ok(test[1] == buf[1], "Expected test[1] to equal buf[1], was: %c, %c\n", test[1], buf[1]);
|
||||
}
|
||||
|
||||
ret = test.GetEnvironmentVariable(_X("SystemRoot"));
|
||||
ok(!!ret, "Expected %%SystemRoot%% to exist\n");
|
||||
ok(test.IsEmpty() == false, "Expected test to have a valid result\n");
|
||||
ok(test == buf, "Expected test to be %s, was %s\n", dbgstrx(buf), dbgstrx(test));
|
||||
|
||||
ret = test.GetEnvironmentVariable(_X("some non existing env var"));
|
||||
ok(!ret, "Expected %%some non existing env var%% to not exist\n");
|
||||
ok(test.IsEmpty() == true, "Expected test to be empty\n");
|
||||
ok(test.GetLength() == 0, "Expected GetLength() to be 0, was: %i\n", test.GetLength());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue