Commit 74f91790 authored by legoc's avatar legoc

Modified testArray.cpp to write different binary encoded files

parent aa1fe13e
......@@ -27,14 +27,32 @@
#include <common/base/PortableByteArray.h>
#include <iostream>
#include <string>
#include <fstream>
using namespace common;
using namespace std;
BOOST_AUTO_TEST_SUITE(suite);
void writeFile(const std::string& encodedString, const std::string& type, int endianness) {
BOOST_AUTO_TEST_CASE(testPrint1)
{
ostringstream os;
if (endianness == common::LITTLE_ENDIAN_ORDER) {
os << "test-" << type << "-" << "little.bin";
}
else {
os << "test-" << type << "-" << "big.bin";
}
ofstream testFile;
testFile.open(os.str().c_str(), ios::binary);
testFile << encodedString;
testFile.close();
}
BOOST_AUTO_TEST_SUITE(suite)
;
BOOST_AUTO_TEST_CASE(testPrint1) {
cout << "BaseTypeToString test" << endl;
cout << BaseTypeToString::convert(PropertyType::INT8) << endl;
cout << BaseTypeToString::convert(PropertyType::INT16) << endl;
......@@ -67,7 +85,7 @@ BOOST_AUTO_TEST_CASE(testPrint1)
cout << "Portable byte array" << endl;
{
int32 intArray[] = {100, -21, 5665787, 45, 9898};
int32 intArray[] = { 100, -21, 5665787, numeric_limits<int32>::min(), numeric_limits<int32>::max() };
common::PortableByteArray<int32> portableByteArray;
string encodedString;
......@@ -76,26 +94,31 @@ BOOST_AUTO_TEST_CASE(testPrint1)
vector<int32> resultArray = portableByteArray.decode(encodedString);
cout << "result size = " << resultArray.size() << endl;
for (int i = 0; i < 5; ++i) {
cout << resultArray[i] << ", ";
cout << "\t" << resultArray[i] << endl;
}
cout << endl;
// Write the encoded string into a file.
writeFile(encodedString, "int32", common::LITTLE_ENDIAN_ORDER);
portableByteArray.encode(intArray, 5, encodedString, common::BIG_ENDIAN_ORDER);
resultArray = portableByteArray.decode(encodedString);
cout << "result size = " << resultArray.size() << endl;
for (int i = 0; i < 5; ++i) {
cout << resultArray[i] << ", ";
cout << "\t" << resultArray[i] << endl;
}
cout << endl;
// Write the encoded string into a file.
writeFile(encodedString, "int32", common::BIG_ENDIAN_ORDER);
}
{
float64 floatArray[] = {100.1, -21.2, 5665787.3, 45.4, 9898.5};
float64 floatArray[] = { 100.1, -21.2, 5665787.3, numeric_limits<float64>::min(), numeric_limits<float64>::max() };
common::PortableByteArray<float64> portableByteArray;
string encodedString;
......@@ -104,22 +127,27 @@ BOOST_AUTO_TEST_CASE(testPrint1)
vector<float64> resultArray = portableByteArray.decode(encodedString);
cout << "result size = " << resultArray.size() << endl;
for (int i = 0; i < 5; ++i) {
cout << resultArray[i] << ", ";
cout << "\t" << resultArray[i] << endl;
}
cout << endl;
// Write the encoded string into a file.
writeFile(encodedString, "float64", common::LITTLE_ENDIAN_ORDER);
portableByteArray.encode(floatArray, 5, encodedString, common::BIG_ENDIAN_ORDER);
resultArray = portableByteArray.decode(encodedString);
cout << "result size = " << resultArray.size() << endl;
for (int i = 0; i < 5; ++i) {
cout << resultArray[i] << ", ";
cout << "\t" << resultArray[i] << endl;
}
cout << endl;
// Write the encoded string into a file.
writeFile(encodedString, "float64", common::BIG_ENDIAN_ORDER);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment