~markwright/scalestack/zeromq

« back to all changes in this revision

Viewing changes to ScaleStack/TestKernel.cc

  • Committer: Eric Day
  • Date: 2010-02-21 10:36:03 UTC
  • Revision ID: eday@oddments.org-20100221103603-u0agc1fsduqhl728
Initial commit with build system and basic module loading.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Scale Stack
 
3
 *
 
4
 * Copyright (C) 2010 Eric Day (eday@oddments.org)
 
5
 * All rights reserved.
 
6
 *
 
7
 * Use and distribution licensed under the BSD license. See the
 
8
 * COPYING file in the root project directory for full text.
 
9
 */
 
10
 
 
11
/**
 
12
 * @file
 
13
 * @brief Kernel Tests
 
14
 */
 
15
 
 
16
#include "config.h"
 
17
 
 
18
#include <ScaleStack/TestCommon.h>
 
19
#include <ScaleStack/Kernel.h>
 
20
 
 
21
TEST_BEGIN(constructor)
 
22
  ScaleStack::Kernel kernel;
 
23
  int argc;
 
24
  char** argv;
 
25
  kernel.getArgcArgv(&argc, &argv);
 
26
  assert(argc == 0);
 
27
  assert(argv == NULL);
 
28
TEST_END
 
29
 
 
30
TEST_BEGIN(constructorArgcArgv)
 
31
  int argc = 1;
 
32
  char* argv[] = { NULL };
 
33
  ScaleStack::Kernel kernel(argc, argv);
 
34
 
 
35
  int test_argc;
 
36
  char** test_argv;
 
37
  kernel.getArgcArgv(&test_argc, &test_argv);
 
38
  assert(test_argc == 1);
 
39
  assert(test_argv == argv);
 
40
TEST_END
 
41
 
 
42
TEST_BEGIN(addModule)
 
43
  ScaleStack::Kernel kernel;
 
44
  kernel.addModule("TestModule");
 
45
 
 
46
  bool pass = false;
 
47
  try
 
48
  {
 
49
    kernel.addModule("TestModule");
 
50
  }
 
51
  catch (ScaleStack::ModuleExists& e)
 
52
  {
 
53
    pass = true;
 
54
  }
 
55
  assert(pass);
 
56
TEST_END
 
57
 
 
58
TEST_BEGIN(getModule)
 
59
  ScaleStack::Kernel kernel;
 
60
  ScaleStack::Module& module = kernel.addModule("TestModule");
 
61
  assert(&module == &kernel.getModule("TestModule"));
 
62
 
 
63
  bool pass = false;
 
64
  try
 
65
  {
 
66
    kernel.getModule("BadModule");
 
67
  }
 
68
  catch (ScaleStack::ModuleNotFound& e)
 
69
  {
 
70
    pass = true;
 
71
  }
 
72
  assert(pass);
 
73
TEST_END
 
74
 
 
75
TEST_BEGIN(getOrAddModule)
 
76
  ScaleStack::Kernel kernel;
 
77
  ScaleStack::Module& module = kernel.addModule("TestModule");
 
78
  assert(&module == &kernel.getOrAddModule("TestModule"));
 
79
 
 
80
  ScaleStack::Module& module2 = kernel.getOrAddModule("TestModule2");
 
81
  assert(&module2 == &kernel.getOrAddModule("TestModule2"));
 
82
  assert(&module != &kernel.getOrAddModule("TestModule2"));
 
83
TEST_END
 
84
 
 
85
TEST_BEGIN(run)
 
86
  ScaleStack::Kernel kernel;
 
87
  kernel.run();
 
88
TEST_END
 
89
 
 
90
TEST_RUNNER_BEGIN(Kernel)
 
91
  TEST_RUN(constructor);
 
92
  TEST_RUN(constructorArgcArgv);
 
93
  TEST_RUN(addModule);
 
94
  TEST_RUN(getModule);
 
95
  TEST_RUN(getOrAddModule);
 
96
  TEST_RUN(run);
 
97
TEST_RUNNER_END