Go to the documentation of this file.00001 #include "mbl_test.h"
00002
00003
00004
00005
00006
00007
00008 #include <vcl_cerrno.h>
00009 #include <vcl_string.h>
00010 #include <vcl_fstream.h>
00011 #include <vcl_ctime.h>
00012 #include <vcl_cstdlib.h>
00013 #include <vcl_iomanip.h>
00014 #include <vul/vul_file.h>
00015 #include <vul/vul_expand_path.h>
00016 #include <mbl/mbl_config.h>
00017
00018
00019
00020 static unsigned replace(char from, char to, vcl_string &s)
00021 {
00022 unsigned c = 0;
00023 for (unsigned i=0; i<s.size(); ++i)
00024 if (s[i] == from)
00025 {
00026 c++;
00027 s[i] = to;
00028 }
00029 return c;
00030 }
00031
00032
00033 vcl_string timestamp()
00034 {
00035 char tmpbuf[128];
00036 vcl_time_t ltime;
00037 struct vcl_tm *today;
00038
00039
00040 vcl_time( <ime );
00041
00042
00043 today = vcl_localtime( <ime );
00044
00045
00046 vcl_strftime( tmpbuf, 128, "%Y-%m-%d %H:%M:%S", today );
00047 return vcl_string(tmpbuf);
00048 }
00049
00050
00051
00052
00053
00054
00055 void mbl_test_save_measurement( const vcl_string &measurement_path, double value)
00056 {
00057 vcl_cout << "<DartMeasurement name=\"" <<
00058 vul_file::strip_directory(measurement_path) <<
00059 "\" type=\"numeric/float\">"<<value<<"</DartMeasurement>" << vcl_endl;
00060
00061 char * cpath = vcl_getenv("MBL_TEST_SAVE_MEASUREMENT_ROOT");
00062 vcl_string path(cpath?cpath:"");
00063 if (path.empty())
00064 path = MBL_CONFIG_TEST_SAVE_MEASUREMENT_ROOT;
00065 if (path.empty())
00066 return;
00067
00068 vcl_string config = MBL_CONFIG_BUILD_NAME;
00069 if (config.empty()) config="DEFAULT_CONFIG";
00070
00071 path += '/' + measurement_path + ".txt";
00072 replace('\\', '/', path);
00073 path = vul_expand_path(path);
00074 vul_file::make_directory_path(vul_file::dirname(path));
00075 vcl_ofstream file(path.c_str(), vcl_ios_app | vcl_ios_out);
00076
00077 if (!file)
00078 vcl_cerr << "ERROR: mbl_test_save_measurement: Unable to open file " << path.c_str()
00079 << "ERRNO: " << errno << '\n';
00080 else
00081 file << timestamp() << ' ' << MBL_CONFIG_BUILD_NAME << ' ' << vcl_setprecision(15) << value << vcl_endl;
00082 }