Author: mjansen Date: Sat Dec 17 19:38:08 2016 New Revision: 73465
URL: http://svn.reactos.org/svn/reactos?rev=73465&view=rev Log: [ATL][ATL_APITEST] Add GetEnvironmentVariable to CString. CORE-12581
Modified: trunk/reactos/sdk/lib/atl/cstringt.h trunk/rostests/apitests/atl/CString.cpp trunk/rostests/apitests/atl/CString.inl
Modified: trunk/reactos/sdk/lib/atl/cstringt.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/sdk/lib/atl/cstringt.h?rev=... ============================================================================== --- trunk/reactos/sdk/lib/atl/cstringt.h [iso-8859-1] (original) +++ trunk/reactos/sdk/lib/atl/cstringt.h [iso-8859-1] Sat Dec 17 19:38:08 2016 @@ -83,6 +83,14 @@ ::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) @@ -199,6 +207,14 @@ _In_ int nSrcLength) { ::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( @@ -452,6 +468,22 @@ 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();
Modified: trunk/rostests/apitests/atl/CString.cpp URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/atl/CString.cpp?r... ============================================================================== --- trunk/rostests/apitests/atl/CString.cpp [iso-8859-1] (original) +++ trunk/rostests/apitests/atl/CString.cpp [iso-8859-1] Sat Dec 17 19:38:08 2016 @@ -5,8 +5,8 @@ * PROGRAMMER: Mark Jansen */
+#include <atlstr.h> #include <apitest.h> -#include <atlstr.h>
struct traits_test @@ -119,12 +119,13 @@ #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 @@ #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 @@
test_trimW(); test_trimA(); + + test_envW(); + test_envA(); }
Modified: trunk/rostests/apitests/atl/CString.inl URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/atl/CString.inl?r... ============================================================================== --- trunk/rostests/apitests/atl/CString.inl [iso-8859-1] (original) +++ trunk/rostests/apitests/atl/CString.inl [iso-8859-1] Sat Dec 17 19:38:08 2016 @@ -356,3 +356,35 @@ 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()); +}