GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Hongli Lai (Phusion) (author)
Sat May 10 03:29:52 -0700 2008
commit  b137282e73bd518d249dc19e5cd17ead933f91b9
tree    50b0b7f7fff3624d716c2242a892a653052df3f0
parent  d31dc2d7f28cef553ae480c6216ecd87ef766ed4
passenger / test / UtilsTest.cpp
100644 101 lines (82 sloc) 2.168 kb
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
#include "tut.h"
#include "Utils.h"
#include <unistd.h>
#include <limits.h>
 
using namespace Passenger;
using namespace std;
 
namespace tut {
  struct UtilsTest {
    vector<string> output;
    string oldPath;
    
    UtilsTest() {
      oldPath = getenv("PATH");
    }
    
    ~UtilsTest() {
      setenv("PATH", oldPath.c_str(), 1);
    }
  };
 
  DEFINE_TEST_GROUP(UtilsTest);
 
  /***** Test split() *****/
 
  TEST_METHOD(1) {
    split("", ':', output);
    ensure_equals(output.size(), 1u);
    ensure_equals(output[0], "");
  }
  
  TEST_METHOD(2) {
    split("hello world", ':', output);
    ensure_equals(output.size(), 1u);
    ensure_equals(output[0], "hello world");
  }
  
  TEST_METHOD(3) {
    split("hello world:foo bar", ':', output);
    ensure_equals(output.size(), 2u);
    ensure_equals(output[0], "hello world");
    ensure_equals(output[1], "foo bar");
  }
  
  TEST_METHOD(4) {
    split("hello world:", ':', output);
    ensure_equals(output.size(), 2u);
    ensure_equals(output[0], "hello world");
    ensure_equals(output[1], "");
  }
  
  TEST_METHOD(5) {
    split(":hello world", ':', output);
    ensure_equals(output.size(), 2u);
    ensure_equals(output[0], "");
    ensure_equals(output[1], "hello world");
  }
  
  TEST_METHOD(6) {
    split("abc:def::ghi", ':', output);
    ensure_equals(output.size(), 4u);
    ensure_equals(output[0], "abc");
    ensure_equals(output[1], "def");
    ensure_equals(output[2], "");
    ensure_equals(output[3], "ghi");
  }
  
  TEST_METHOD(7) {
    split("abc:::def", ':', output);
    ensure_equals(output.size(), 4u);
    ensure_equals(output[0], "abc");
    ensure_equals(output[1], "");
    ensure_equals(output[2], "");
    ensure_equals(output[3], "def");
  }
  
  
  /**** Test findSpawnServer() ****/
  
  TEST_METHOD(8) {
    // If $PATH is empty, it should not find anything.
    setenv("PATH", "", 1);
    ensure_equals(findSpawnServer(), "");
  }
  
  TEST_METHOD(9) {
    // It should ignore relative paths.
    setenv("PATH", "../bin", 1);
    ensure_equals(findSpawnServer(), "");
  }
  
  TEST_METHOD(10) {
    char cwd[PATH_MAX];
    string binpath(getcwd(cwd, sizeof(cwd)));
    binpath.append("/../bin");
    setenv("PATH", binpath.c_str(), 1);
    ensure("Spawn server is found.", !findSpawnServer().empty());
  }
}