feisty meow concerns codebase  2.140
test_unique_id.cpp
Go to the documentation of this file.
1 /*****************************************************************************\
2 * *
3 * Name : t_unique_id *
4 * Author : Chris Koeritz *
5 * *
6 *******************************************************************************
7 * Copyright (c) 2005-$now By Author. This program is free software; you can *
8 * redistribute it and/or modify it under the terms of the GNU General Public *
9 * License as published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) any later version. This is online at: *
11 * http://www.fsf.org/copyleft/gpl.html *
12 * Please send any updates to: fred@gruntose.com *
13 \*****************************************************************************/
14 
16 #include <basis/astring.h>
17 #include <basis/guards.h>
19 #include <mathematics/chaos.h>
20 #include <structures/unique_id.h>
22 #include <unit_test/unit_base.h>
23 
24 #ifdef DEBUG_STACK
25  #define LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), to_print)
26 #endif
27 
28 using namespace application;
29 using namespace basis;
31 using namespace mathematics;
32 using namespace filesystem;
33 using namespace loggers;
34 using namespace structures;
35 using namespace textual;
36 using namespace timely;
37 using namespace unit_test;
38 
39 #include <stdlib.h>
40 #include <string.h>
41 
43 
44 class test_unique_id : public virtual unit_base, public virtual application_shell
45 {
46 public:
47  test_unique_id() {}
48  DEFINE_CLASS_NAME("test_unique_id");
49  int execute();
50 };
51 
52 HOOPLE_MAIN(test_unique_id, );
53 
55 
56 int test_unique_id::execute()
57 {
58  FUNCDEF("execute");
59  unique_int ted(25);
60  unique_int jed;
61 
62  ASSERT_TRUE(ted.raw_id(), "testing non-zero should not claim was zero");
63  ASSERT_TRUE(!jed, "testing zero should claim was zero");
64  ASSERT_TRUE(!!ted, "testing non-zero doubled should not claim was zero");
65  ASSERT_TRUE(!!!jed, "testing zero doubled should claim was zero");
66 
67  unique_int med(25);
68  unique_int fed(0);
69 
70  ASSERT_EQUAL(med.raw_id(), ted.raw_id(), "testing equality 1 should have correct result");
71  ASSERT_EQUAL(fed.raw_id(), jed.raw_id(), "testing equality 2 should have correct result");
72  ASSERT_INEQUAL(med.raw_id(), jed.raw_id(), "testing equality 3 should have correct result");
73  ASSERT_INEQUAL(fed.raw_id(), ted.raw_id(), "testing equality 4 should have correct result");
74 
75  ASSERT_FALSE(med != ted, "equality operator 1 should have correct result");
76  ASSERT_FALSE(fed != jed, "equality operator 2 should have correct result");
77  ASSERT_FALSE(med == jed, "equality operator 3 should have correct result");
78  ASSERT_FALSE(fed == ted, "equality operator 4 should have correct result");
79 
80  return final_report();
81 }
82 
The application_shell is a base object for console programs.
uniquifier raw_id() const
Returns the held identifier in its native form.
Definition: unique_id.h:57
A unique identifier based on integers.
Definition: unique_id.h:97
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition: enhance_cpp.h:45
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition: enhance_cpp.h:57
Provides macros that implement the 'main' program of an application.
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
A platform independent way to obtain the timestamp of a file.
Definition: byte_filer.cpp:37
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
Definition: averager.h:21
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55
#include <time.h>
Definition: earth_time.cpp:37
Useful support functions for unit testing, especially within hoople.
Definition: unit_base.cpp:35
HOOPLE_MAIN(test_unique_id,)
#define ASSERT_EQUAL(a, b, test_name)
Definition: unit_base.h:38
#define ASSERT_TRUE(a, test_name)
Definition: unit_base.h:46
#define ASSERT_FALSE(a, test_name)
Definition: unit_base.h:50
#define ASSERT_INEQUAL(a, b, test_name)
Definition: unit_base.h:42