mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Test UTF-16 output of GetUserName
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unistd.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <scxcorelib/scxstrencodingconv.h>
|
||||
#include "getusername.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using SCXCoreLib::Utf16leToUtf8;
|
||||
|
||||
TEST(GetUserName,simple)
|
||||
{
|
||||
// allocate a WCHAR_T buffer to receive username
|
||||
@@ -14,10 +21,17 @@ TEST(GetUserName,simple)
|
||||
ASSERT_EQ(1, result);
|
||||
|
||||
// get expected username
|
||||
const char *username = getlogin();
|
||||
string username = string(getlogin());
|
||||
|
||||
// GetUserName sets lpnSize to length of username including null
|
||||
ASSERT_EQ(strlen(username)+1, lpnSize);
|
||||
ASSERT_EQ(username.size()+1, lpnSize);
|
||||
|
||||
// TODO: ASSERT_STREQ(username, Utf16leToUtf8(lpBuffer))
|
||||
// copy UTF-16 bytes from lpBuffer to vector for conversion
|
||||
vector<unsigned char> input(reinterpret_cast<unsigned char *>(&lpBuffer[0]),
|
||||
reinterpret_cast<unsigned char *>(&lpBuffer[lpnSize-1]));
|
||||
// convert to UTF-8 for assertion
|
||||
string output;
|
||||
Utf16leToUtf8(input, output);
|
||||
|
||||
EXPECT_EQ(username, output);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user