Factor out using directives
This commit is contained in:
parent
6699091f7b
commit
3ab3408378
2 changed files with 7 additions and 16 deletions
|
@ -7,11 +7,6 @@
|
|||
#include <vector>
|
||||
#include <scxcorelib/scxstrencodingconv.h>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
using SCXCoreLib::Utf8ToUtf16le;
|
||||
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724432(v=vs.85).aspx
|
||||
// Sets errno to:
|
||||
// ERROR_INVALID_PARAMETER - parameter is not valid
|
||||
|
@ -79,9 +74,9 @@ BOOL GetUserName(WCHAR_T *lpBuffer, LPDWORD lpnSize)
|
|||
}
|
||||
|
||||
// Convert to char * to WCHAR_T * (UTF-8 to UTF-16 LE w/o BOM)
|
||||
string input = string(userName);
|
||||
vector<unsigned char> output;
|
||||
Utf8ToUtf16le(input, output);
|
||||
std::string input(userName);
|
||||
std::vector<unsigned char> output;
|
||||
SCXCoreLib::Utf8ToUtf16le(input, output);
|
||||
|
||||
if (output.size()/2 + 1 > *lpnSize) {
|
||||
errno = ERROR_INSUFFICIENT_BUFFER;
|
||||
|
|
|
@ -5,10 +5,6 @@
|
|||
#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
|
||||
|
@ -21,7 +17,7 @@ TEST(GetUserName,simple)
|
|||
ASSERT_EQ(1, result);
|
||||
|
||||
// get expected username
|
||||
string username = string(getlogin());
|
||||
std::string username(getlogin());
|
||||
|
||||
// GetUserName sets lpnSize to length of username including null
|
||||
ASSERT_EQ(username.size()+1, lpnSize);
|
||||
|
@ -30,10 +26,10 @@ TEST(GetUserName,simple)
|
|||
unsigned char *begin = reinterpret_cast<unsigned char *>(&lpBuffer[0]);
|
||||
// -1 to skip null; *2 because UTF-16 encodes two bytes per character
|
||||
unsigned char *end = begin + (lpnSize-1)*2;
|
||||
vector<unsigned char> input(begin, end);
|
||||
std::vector<unsigned char> input(begin, end);
|
||||
// convert to UTF-8 for assertion
|
||||
string output;
|
||||
Utf16leToUtf8(input, output);
|
||||
std::string output;
|
||||
SCXCoreLib::Utf16leToUtf8(input, output);
|
||||
|
||||
EXPECT_EQ(username, output);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue