File: PoolOptionsTest.cpp

package info (click to toggle)
ruby-passenger 3.0.13debian-1%2Bdeb7u2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,920 kB
  • sloc: cpp: 99,104; ruby: 18,098; ansic: 9,846; sh: 8,632; python: 141; makefile: 30
file content (116 lines) | stat: -rw-r--r-- 3,751 bytes parent folder | download
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "TestSupport.h"
#include "PoolOptions.h"

using namespace Passenger;
using namespace std;

namespace tut {
	struct PoolOptionsTest {
	};

	DEFINE_TEST_GROUP(PoolOptionsTest);

	// Test the PoolOptions constructors and toVector().
	TEST_METHOD(1) {
		PoolOptions options;
		options.appRoot     = "/foo";
		options.frameworkSpawnerTimeout = 123;
		options.appSpawnerTimeout       = 456;
		options.maxRequests = 789;
		
		vector<string> args;
		args.push_back("abc");
		args.push_back("def");
		options.toVector(args);
		
		PoolOptions copy(args, 2);
		ensure_equals(options.appRoot, copy.appRoot);
		ensure_equals(options.rights, copy.rights);
		ensure_equals(options.environment, copy.environment);
		ensure_equals(options.spawnMethod, copy.spawnMethod);
		ensure_equals(options.appType, copy.appType);
		ensure_equals(options.frameworkSpawnerTimeout, copy.frameworkSpawnerTimeout);
		ensure_equals(options.appSpawnerTimeout, copy.appSpawnerTimeout);
		ensure_equals(options.maxRequests, copy.maxRequests);
	}
	
	// Test empty environmentVariables serialization and deserialization.
	TEST_METHOD(2) {
		PoolOptions options;
		vector<string> args;
		options.toVector(args);
		
		PoolOptions options2(args);
		ensure_equals(options2.environmentVariables->getItems()->size(), 0u);
	}
	
	// Test single item environmentVariables serialization and deserialization.
	TEST_METHOD(3) {
		PoolOptions options;
		SimpleStringListCreatorPtr list = ptr(new SimpleStringListCreator());
		vector<string> args;
		list->items->push_back("hello");
		list->items->push_back("world !!");
		options.environmentVariables = list;
		options.toVector(args);
		
		PoolOptions options2(args);
		const StringListPtr list2 = options2.environmentVariables->getItems();
		ensure_equals(list2->size(), 2u);
		ensure_equals(list2->at(0), "hello");
		ensure_equals(list2->at(1), "world !!");
	}
	
	// Test multiple items environmentVariables serialization and deserialization.
	TEST_METHOD(4) {
		PoolOptions options;
		SimpleStringListCreatorPtr list = ptr(new SimpleStringListCreator());
		vector<string> args;
		list->items->push_back("hello");
		list->items->push_back("world !!");
		list->items->push_back("PATH");
		list->items->push_back("/usr/local/bin");
		options.environmentVariables = list;
		options.toVector(args);
		
		PoolOptions options2(args);
		const StringListPtr list2 = options2.environmentVariables->getItems();
		ensure_equals(list2->size(), 4u);
		ensure_equals(list2->at(0), "hello");
		ensure_equals(list2->at(1), "world !!");
		ensure_equals(list2->at(2), "PATH");
		ensure_equals(list2->at(3), "/usr/local/bin");
	}
	
	// Calling toVector() with storeEnvVars = false on a PoolOption object that
	// has no environment variables works, and the resulting data can be unserialized.
	TEST_METHOD(5) {
		PoolOptions options;
		vector<string> args;
		options.appRoot = "hello";
		options.toVector(args, false);
		
		PoolOptions options2(args);
		ensure_equals(options2.appRoot, "hello");
		ensure_equals(options2.environmentVariables, StringListCreatorPtr());
	}
	
	// Calling toVector() with storeEnvVars = false on a PoolOption object that
	// has no environment variables works, and the resulting data can be unserialized.
	TEST_METHOD(6) {
		PoolOptions options;
		SimpleStringListCreatorPtr list = ptr(new SimpleStringListCreator());
		vector<string> args;
		list->items->push_back("hello");
		list->items->push_back("world");
		list->items->push_back("foo");
		list->items->push_back("bar");
		options.appRoot = "hello";
		options.environmentVariables = list;
		options.toVector(args, false);
		
		PoolOptions options2(args);
		ensure_equals(options2.appRoot, "hello");
		ensure_equals(options2.environmentVariables, StringListCreatorPtr());
	}
}