00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef WIOTOOLS_TEST_H
00026 #define WIOTOOLS_TEST_H
00027
00028 #include <string>
00029 #include <fstream>
00030
00031 #include <cxxtest/TestSuite.h>
00032
00033 #include "../WIOTools.h"
00034
00035
00036
00037
00038 class WIOToolsTest : public CxxTest::TestSuite
00039 {
00040 public:
00041
00042
00043
00044
00045 void testByteOrderSwitching( void )
00046 {
00047 uint32_t x = 1;
00048 TS_ASSERT_EQUALS( x, 1 );
00049 x = switchByteOrder( x );
00050 TS_ASSERT_EQUALS( x, 16777216 );
00051 x = switchByteOrder( x );
00052 TS_ASSERT_EQUALS( x, 1 );
00053 }
00054
00055
00056
00057
00058 void testByteOrderSwitchingOnFloats( void )
00059 {
00060 double x = 3.141592653589793238462643383279502884197169399375105820974;
00061 double original = x;
00062 x = switchByteOrder( x );
00063 TS_ASSERT_DIFFERS( x, original );
00064 x = switchByteOrder( x );
00065 TS_ASSERT_EQUALS( x, original );
00066 }
00067
00068
00069
00070
00071 void testByteOrderSwitchingOnSingleBytes( void )
00072 {
00073 char x = 1;
00074 TS_ASSERT_EQUALS( switchByteOrder( x ), x );
00075 }
00076
00077
00078
00079
00080
00081 void testByteOrderSwitchOnArray( void )
00082 {
00083 uint32_t x[] = { 1, 16777216 };
00084 switchByteOrderOfArray( x, 2 );
00085 TS_ASSERT_EQUALS( x[0], 16777216 );
00086 TS_ASSERT_EQUALS( x[1], 1 );
00087 }
00088
00089
00090
00091
00092 void testReadFileIntoString( void )
00093 {
00094 std::string expected = "Hello Pansen!\r\n";
00095 std::string actual = readFileIntoString( boost::filesystem::path( W_FIXTURE_PATH + "hello.world" ) );
00096 TS_ASSERT_EQUALS( expected, actual );
00097 }
00098
00099
00100
00101
00102 void testWriteStringIntoFile( void )
00103 {
00104 std::string content = "Hello Pansen!\r\n";
00105 boost::filesystem::path fpath = tempFileName();
00106 writeStringIntoFile( fpath, content );
00107
00108 std::ifstream input( fpath.file_string().c_str() );
00109 std::string actual;
00110 actual.assign( ( std::istreambuf_iterator< char >( input ) ), std::istreambuf_iterator< char >() );
00111 input.close();
00112 TS_ASSERT_EQUALS( content, actual );
00113 TS_ASSERT( boost::filesystem::exists( fpath ) );
00114 boost::filesystem::remove( fpath );
00115 }
00116 };
00117
00118 #endif // WIOTOOLS_TEST_H