File: ut_MeterExec.cpp

package info (click to toggle)
vzlogger 0.8.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,140 kB
  • sloc: cpp: 12,020; sh: 331; ansic: 157; makefile: 25
file content (66 lines) | stat: -rw-r--r-- 1,967 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "gtest/gtest.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "Options.hpp"
#include "protocols/MeterExec.hpp"

// this is a dirty hack. we should think about better ways/rules to link against the
// test objects.
// e.g. single files in the tests directory that just include the real file. This way one
// will avoid multiple includes of the same file in a different test case
// (or linking against the real file from the CMakeLists.txt)

// #include "../src/protocols/MeterExec.cpp"

int writes(int fd, const char *str);

TEST(MeterExec, basic) {
	char tempfilename[L_tmpnam + 1];
	ASSERT_NE(tmpnam(tempfilename), (char *)0);
	std::list<Option> options;
	options.push_back(Option("command", tempfilename));

	// test without format option
	MeterExec m(options);
	ASSERT_STREQ(m.command(), tempfilename) << "devicename not eq " << tempfilename;

	EXPECT_EQ(0, m.close());
}

TEST(MeterExec, format1) {
	char tempfilename[L_tmpnam + 1];
	ASSERT_NE(tmpnam(tempfilename), (char *)0);
	std::list<Option> options;
	options.push_back(Option("command", tempfilename));
	options.push_back(Option("format", (char *)"$v"));

	MeterExec m(options);
	// todo check here whether format is correctly parsed
	EXPECT_EQ(0, m.close());
}

TEST(MeterExec, format2) {
	char tempfilename[L_tmpnam + 1];
	ASSERT_NE(tmpnam(tempfilename), (char *)0);
	std::list<Option> options;
	options.push_back(Option("command", tempfilename));
	options.push_back(Option("format", (char *)"$i : $v"));

	MeterExec m(options);
	// todo check here whether format is correctly parsed
	EXPECT_EQ(0, m.close());
}

TEST(MeterExec, format3) {
	char tempfilename[L_tmpnam + 1];
	ASSERT_NE(tmpnam(tempfilename), (char *)0);
	std::list<Option> options;
	options.push_back(Option("command", tempfilename));
	options.push_back(Option("format", (char *)"$t;$i : $v"));

	MeterExec m(options);
	// todo check here whether format is correctly parsed
	EXPECT_EQ(0, m.close());
}