Object Initialization User Code

Object initialization user code serves two purposes. The first is to provide initial values to global constants and global references. The second to create the member initializer section of constructors that are defined by VectorCAST.
 

Global object example:

If a declaration looked like the following in the UUT, VectorCAST would need to initialize it at the point it defines it.
 

extern const int extern_global;
 

For example, const int extern_global; would cause a compile error. When we actually define it, we must provide an initial value to extern_global.

--

/*** BEGIN INITIALIZATION OBJECTS ***/
int SOME_VCAST_OBJECT;
/*** END INITIALIZATION OBJECTS ***/

const int extern_global

/*** BEGIN INITIALIZATION CODE ***/
= SOME_VCAST_OBJECT
/*** END INITIALIZATION CODE ***/


A similar process is applied to constructors:

class B : public A {
  public:
    B(int a);
    const int b;
};

/*** BEGIN INITIALIZATION OBJECTS ***/
int SOME_VCAST_OBJECT1;
int SOME_VCAST_OBJECT2;
/*** END INITIALIZATION OBJECTS ***/

B::B(int a)

/*** BEGIN INITIALIZATION CODE ***/
: A(SOME_VCAST_OBJECT1), b(SOME_VCAST_OBJECT2)
/*** END INITIALIZATION CODE ***/

{
 // body of B::B
}


You should have access to all of your types and global objects from within these user code types. The caveat is that you must know the scope of type of user code. Hopefully the examples above will answer your questions. If you want to see the actual place that the user code is inserted, open the S0000009.cpp file and search for "VCAST_INIT_OBJ". 
 



Article ID: 1493
Last updated: 2019-11-04
Revision: 4
VectorCAST -> C++ Unit Testing -> Object Initialization User Code
https://kb.vector.com/entry/1493/