Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added test and processed comments from the merge thread.
  • Loading branch information
wilcob authored and wilcob committed Apr 7, 2015
commit 22592065cec1b5ccde9c5d0b0d71c6941e75601b
5 changes: 4 additions & 1 deletion include/CppUTest/CommandLineTestRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ class CommandLineTestRunner

static int RunAllTests(int ac, const char** av);
static int RunAllTests(int ac, char** av);
static int RunAllTests(int ac, wchar_t** av);
static int RunAllTests(int ac, const wchar_t** av);
static int RunAllTests( int ac, wchar_t** av );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have the const, do we need the non-const?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For symmetry I think it would be best, although the char one might just be there for historical reasons that it was the first 'RunAllTests' function.

CommandLineTestRunner(int ac, const char** av, TestOutput*, TestRegistry* registry);

static char** ConvertWideArgumentsToNormal( int ac, const wchar_t** av );

virtual ~CommandLineTestRunner();
int runAllTestsMain();

Expand Down
31 changes: 18 additions & 13 deletions src/CppUTest/CommandLineTestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,34 @@ int CommandLineTestRunner::RunAllTests(int ac, const char** av)
return result;
}

int CommandLineTestRunner::RunAllTests( int ac, wchar_t** av )
int CommandLineTestRunner::RunAllTests( int ac, wchar_t** av ) {
return RunAllTests( ac, const_cast<const wchar_t**> ( av ) );
}

int CommandLineTestRunner::RunAllTests( int ac, const wchar_t** av )
{
char** avc = new char*[ac];
for ( int i = 0; i < ac; i++ ) {
size_t len = wcslen( av[i] ) + 1;
avc[i] = new char[len];
wcstombs_s( 0 , avc[i], sizeof(char)*len, av[i], len );
}
int result = 0;
char** avc = ConvertWideArgumentsToNormal( ac, av );

try {
RunAllTests( ac, avc );
}
catch ( ... ) {
}
int result = RunAllTests( ac, avc );

for ( int i = 0; i < ac; i++ ) {
delete[] avc[i];
}
delete[] avc;

return result;
}

char** CommandLineTestRunner::ConvertWideArgumentsToNormal( int ac, const wchar_t** av ) {
char** avc = new char*[ac];
for( int i = 0; i < ac; i++ ) {
size_t len = wcslen( av[i] ) + 1;
avc[i] = new char[len];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the new here and the delete at another scope is asking for trouble :(

wcstombs( avc[i], av[i], len );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversion methods of Lib C would need to be in PlatformSpecific...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting challenge considering the lack of experience and access to half the current platforms.

}
return avc;
}

int CommandLineTestRunner::runAllTestsMain()
{
int testResult = 0;
Expand Down
16 changes: 16 additions & 0 deletions tests/CommandLineTestRunnerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ TEST(CommandLineTestRunner, NoPluginsAreInstalledAtTheEndOfARunWhenTheArgumentsA
LONGS_EQUAL(0, registry.countPlugins());
}

TEST( CommandLineTestRunner, VerifyWideToNormalConversions ) {
const wchar_t* argv[] = { L"dummy.exe", L"-fdskjnfkds" };
int ac = 2;

char** avc = CommandLineTestRunner::ConvertWideArgumentsToNormal( ac, argv );

STRCMP_EQUAL( "dummy.exe", avc[0] );
STRCMP_EQUAL( "-fdskjnfkds", avc[1] );

for( int i = 0; i < ac; i++ ) {
delete[] avc[i];
}
delete[] avc;
}


struct TestOutputCheckingCommandLineTestRunner : public CommandLineTestRunner
{
TestOutputCheckingCommandLineTestRunner(int ac, const char** av, TestOutput* output, TestRegistry* registry) :
Expand Down