Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F123419
UTFStringTest.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
UTFStringTest.cpp
View Options
/*
* File: UTFStringTest.cpp
* Author: sean
*
* Created on 02-Oct-2014, 13:13:18
*/
#include
<stdlib.h>
#include
<iostream>
#include
<echo/UTF8String.h>
using
namespace
Echo
;
void
BasicIteratorTest
()
{
std
::
cout
<<
"UTFStringTest BasicIteratorTest"
<<
std
::
endl
;
UTF8String
twochars
(
"
\xe6\x97\xa5\xd1\x88
"
);
UTF8String
::
iterator
it
=
twochars
.
begin
();
UTF32Code
code
=
*
it
;
if
(
code
!=
0x65e5
)
{
std
::
cout
<<
"%TEST_FAILED% time=0 testname=BasicIteratorTest (UTFStringTest) message=Incorrect code returned."
<<
std
::
endl
;
}
if
(
it
!=
twochars
.
begin
())
{
std
::
cout
<<
"%TEST_FAILED% time=0 testname=BasicIteratorTest (UTFStringTest) message=Iterator has incorrect value."
<<
std
::
endl
;
}
}
void
IteratorLoopTest
()
{
std
::
cout
<<
"UTFStringTest IteratorLoopTest"
<<
std
::
endl
;
//ASCII strings below 127 are UTF8 compatible, so this should allow us to test iterator loops and see the correct output.
const
std
::
string
TEST_STRING
=
"abcdef"
;
UTF8String
testString
(
TEST_STRING
);
UTF8String
::
iterator
it
=
testString
.
begin
();
UTF8String
::
iterator
itEnd
=
testString
.
end
();
std
::
string
output
;
while
(
it
!=
itEnd
)
{
UTF32Code
code
=
*
it
;
//This is only possible because ASCII strings are UTF8 compatible. If we were using characters > 127 then this wouldn't work.
output
+=
static_cast
<
char
>
(
code
);
it
++
;
}
if
(
output
!=
TEST_STRING
)
{
std
::
cout
<<
"%TEST_FAILED% time=0 testname=IteratorLoopTest (UTFStringTest) message=Reconstructed output value does not match input value."
<<
std
::
endl
;
}
}
void
OperatorTest
()
{
UTF8String
utf8String
(
"Hello"
);
std
::
string
normalString
(
" world"
);
UTF8String
finalString
;
finalString
+=
utf8String
;
if
(
finalString
.
GetContent
()
!=
"Hello"
)
{
std
::
cout
<<
"%TEST_FAILED% time=0 testname=OperatorTest (UTFStringTest) message=operator+=(UTFStringTest) failed."
<<
std
::
endl
;
}
finalString
+=
normalString
;
if
(
finalString
.
GetContent
()
!=
"Hello world"
)
{
std
::
cout
<<
"%TEST_FAILED% time=0 testname=OperatorTest (UTFStringTest) message=operator+=(std::string) failed."
<<
std
::
endl
;
}
UTF8String
excl
(
"!"
);
UTF32Code
code
=
*
excl
.
begin
();
finalString
+=
code
;
if
(
finalString
.
GetContent
()
!=
"Hello world!"
)
{
std
::
cout
<<
"%TEST_FAILED% time=0 testname=OperatorTest (UTFStringTest) message=operator+=(UTF32Code) failed."
<<
std
::
endl
;
}
}
int
main
(
int
argc
,
char
**
argv
)
{
std
::
cout
<<
"%SUITE_STARTING% UTFStringTest"
<<
std
::
endl
;
std
::
cout
<<
"%SUITE_STARTED%"
<<
std
::
endl
;
std
::
cout
<<
"%TEST_STARTED% BasicIteratorTest (UTFStringTest)"
<<
std
::
endl
;
BasicIteratorTest
();
std
::
cout
<<
"%TEST_FINISHED% time=0 BasicIteratorTest (UTFStringTest)"
<<
std
::
endl
;
std
::
cout
<<
"%TEST_STARTED% IteratorLoopTest (UTFStringTest)
\n
"
<<
std
::
endl
;
IteratorLoopTest
();
std
::
cout
<<
"%TEST_FINISHED% time=0 IteratorLoopTest (UTFStringTest)"
<<
std
::
endl
;
std
::
cout
<<
"%TEST_STARTED% OperatorTest (UTFStringTest)
\n
"
<<
std
::
endl
;
OperatorTest
();
std
::
cout
<<
"%TEST_FINISHED% time=0 OperatorTest (UTFStringTest)"
<<
std
::
endl
;
std
::
cout
<<
"%SUITE_FINISHED% time=0"
<<
std
::
endl
;
return
(
EXIT_SUCCESS
);
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Wed, Jan 15, 10:37 PM (4 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
72069
Default Alt Text
UTFStringTest.cpp (3 KB)
Attached To
Mode
rEE Echo 3
Attached
Detach File
Event Timeline
Log In to Comment