Skip to content

Wide space input support #574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions include/CppUTest/CommandLineTestRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "TestOutput.h"
#include "CommandLineArguments.h"
#include "TestFilter.h"
#include <cwchar>
Copy link
Member

Choose a reason for hiding this comment

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

Direct dependencies with Lib C aren't allowed in CppUTest. You'd need to wrap the methods in PlatformSpecific to deal with portability to "less supported" platforms.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, that makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

@basvodde I don't know offhand about wchar_t. What I do know is that, due to limited memory, we had to use the non-std-C++ lib option. I suppose that means at least the conversion functions won't be available for the cl2000.

Copy link
Contributor

Choose a reason for hiding this comment

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

seems to be a c lib though.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, though we are going to have problems with wchar_t not being a type without #include...


class JUnitTestOutput;
class TestRegistry;
Expand All @@ -49,8 +50,12 @@ class CommandLineTestRunner

static int RunAllTests(int ac, const char** av);
static int RunAllTests(int ac, char** av);
static int RunAllTests(int ac, const wchar_t** av);
static int RunAllTests( int ac, wchar_t** av );
Copy link
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
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
28 changes: 28 additions & 0 deletions src/CppUTest/CommandLineTestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,34 @@ int CommandLineTestRunner::RunAllTests(int ac, const char** av)
return result;
}

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 = ConvertWideArgumentsToNormal( ac, av );

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
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
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
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