feisty meow concerns codebase  2.140
test_identity.cpp
Go to the documentation of this file.
1 /*****************************************************************************\
2 * *
3 * Name : octopus identity test *
4 * Author : Chris Koeritz *
5 * *
6 * Purpose: *
7 * *
8 * Checks out the client identification methods in octopus. *
9 * *
10 *******************************************************************************
11 * Copyright (c) 2002-$now By Author. This program is free software; you can *
12 * redistribute it and/or modify it under the terms of the GNU General Public *
13 * License as published by the Free Software Foundation; either version 2 of *
14 * the License or (at your option) any later version. This is online at: *
15 * http://www.fsf.org/copyleft/gpl.html *
16 * Please send any updates to: fred@gruntose.com *
17 \*****************************************************************************/
18 
21 #include <basis/astring.h>
22 #include <loggers/console_logger.h>
25 #include <octopus/entity_defs.h>
27 #include <octopus/infoton.h>
28 #include <octopus/octopus.h>
29 #include <octopus/tentacle.h>
31 #include <unit_test/unit_base.h>
32 
33 using namespace application;
34 using namespace basis;
35 //using namespace configuration;
36 using namespace loggers;
37 using namespace mathematics;
38 using namespace octopi;
39 //using namespace sockets;
40 using namespace textual;
41 using namespace unit_test;
42 
43 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), astring(s))
44 
46 
47 class test_octopus_identity : virtual public unit_base, virtual public application_shell
48 {
49 public:
50  test_octopus_identity() : application_shell() {}
51 //class_name()
52  DEFINE_CLASS_NAME("test_octopus_identity");
53  virtual int execute();
54 };
55 
56 int test_octopus_identity::execute()
57 {
58  FUNCDEF("execute")
59  octopus logos("local", 18 * MEGABYTE);
60 
62  octopus_request_id junk_id = octopus_request_id::randomized_id();
63  // bogus right now.
64 
65  byte_array packed;
66  ide->pack(packed);
67  if (ide->packed_size() != packed.length())
68  deadly_error(class_name(), "packing test",
69  astring("the packed size was different than expected."));
70 
71  outcome ret = logos.evaluate(ide, junk_id);
72  if (ret != tentacle::OKAY)
73  deadly_error(class_name(), "evaluate test",
74  astring("the evaluation failed with an error ")
75  + tentacle::outcome_name(ret));
76 LOG("point a");
77 
78  octopus_request_id response_id; // based on bogus from before.
79  infoton *response = logos.acquire_result(junk_id._entity, response_id);
80  if (!response)
81  deadly_error(class_name(), "acquire test",
82  astring("the acquire_result failed to produce a result."));
83 
84  identity_infoton *new_id = dynamic_cast<identity_infoton *>(response);
85  if (!new_id)
86  deadly_error(class_name(), "casting",
87  astring("the returned infoton is not the right type."));
88 
89  octopus_entity my_ide = new_id->_new_name;
90 
91 LOG(astring("new id is: ") + my_ide.text_form());
92 
93  if (my_ide.blank())
94  deadly_error(class_name(), "retrieving id",
95  astring("the new entity id is blank."));
96 
97 
98  LOG("octopus:: identity works for those functions tested.");
99 
100  return 0;
101 }
102 
103 HOOPLE_MAIN(test_octopus_identity, )
104 
The application_shell is a base object for console programs.
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
Outcomes describe the state of completion for an operation.
Definition: outcome.h:31
Encapsulates just the action of identifying an octopus user.
An infoton is an individual request parcel with accompanying information.
Definition: infoton.h:32
Provides a way of identifying users of an octopus object.
Definition: entity_defs.h:35
Identifies requests made on an octopus by users.
Definition: entity_defs.h:114
Octopus is a design pattern for generalized request processing systems.
Definition: octopus.h:47
Manages a service within an octopus by processing certain infotons.
Definition: tentacle.h:36
#define deadly_error(c, f, i)
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition: enhance_cpp.h:42
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition: enhance_cpp.h:54
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition: hoople_main.h:61
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
const int MEGABYTE
Number of bytes in a megabyte.
Definition: definitions.h:135
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
void pack(basis::byte_array &packed_form, const set< contents > &to_pack)
provides a way to pack any set that stores packable objects.
Definition: set.h:131
int packed_size(const byte_array &packed_form)
Reports the size required to pack a byte array into a byte array.
Useful support functions for unit testing, especially within hoople.
Definition: unit_base.cpp:35
#define LOG(s)
#define test(expr)