MCPcopy Create free account
hub / github.com/davisking/dlib / test_strings

Function test_strings

dlib/test/serialize.cpp:1035–1112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1033// ----------------------------------------------------------------------------------------
1034
1035 void test_strings()
1036 {
1037 string str1 = "stuff";
1038 char buf[6];
1039 buf[0] = 0;
1040 buf[1] = 1;
1041 buf[2] = 2;
1042 buf[3] = 0;
1043 buf[4] = 3;
1044 buf[5] = 3;
1045
1046 dlib::serialize("ser_test_string.dat") << str1 << buf << "morestuff" << "";
1047
1048 string str2, str3, str4;
1049 char buf2[6];
1050 memset(buf2,0,sizeof(buf2));
1051 dlib::deserialize("ser_test_string.dat") >> str2 >> buf2 >> str3 >> str4;
1052 DLIB_TEST(str2 == "stuff");
1053 DLIB_TEST(str3 == "morestuff");
1054 DLIB_TEST(str4 == "");
1055 DLIB_TEST(buf2[0] == 0);
1056 DLIB_TEST(buf2[1] == 1);
1057 DLIB_TEST(buf2[2] == 2);
1058 DLIB_TEST(buf2[3] == 0);
1059 DLIB_TEST(buf2[4] == 3);
1060 DLIB_TEST(buf2[5] == 3);
1061
1062
1063 ofstream fout("ser_test_string.dat", ios::binary);
1064 dlib::serialize(str1, fout);
1065 dlib::serialize(buf, fout);
1066 dlib::serialize("morestuff", fout);
1067 fout.close();
1068 ifstream fin("ser_test_string.dat", ios::binary);
1069 memset(buf2,0,sizeof(buf2));
1070 str2.clear();
1071 str3.clear();
1072 dlib::deserialize(str2, fin);
1073 dlib::deserialize(buf2, fin);
1074 dlib::deserialize(str3, fin);
1075
1076 DLIB_TEST(str2 == "stuff");
1077 DLIB_TEST(str3 == "morestuff");
1078 DLIB_TEST(buf2[0] == 0);
1079 DLIB_TEST(buf2[1] == 1);
1080 DLIB_TEST(buf2[2] == 2);
1081 DLIB_TEST(buf2[3] == 0);
1082 DLIB_TEST(buf2[4] == 3);
1083 DLIB_TEST(buf2[5] == 3);
1084
1085
1086
1087 // make sure ramdump() overloads compile and work.
1088 {
1089 matrix<double,2,2> a = {1,2,3,4};
1090 const matrix<double,2,2> b = {3,2,3,4};
1091 dlib::serialize("ramdump_mat.dat") << ramdump(a) << ramdump(b);
1092 matrix<double,2,2> A, B;

Callers 1

perform_testMethod · 0.85

Calls 6

ramdumpFunction · 0.85
serializeFunction · 0.70
deserializeFunction · 0.70
closeMethod · 0.45
clearMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected