A4 programming
//------------------------------------------------ // NAME : YOUR NAME // STUDENT# : ####### // // COURSE : COMP 2160, SECTION: A01 // INSTRUCTOR: Stela H. Seo //------------------------------------------------ //------------------------------------------------------------------------------ // INCLUDE HEADERS //------------------------------------------------------------------------------ #include <stdlib.h> #include <stdio.h> #include "ObjectManager.h" //------------------------------------------------------------------------------ // CONSTANTS AND TYPES //------------------------------------------------------------------------------ #define MEMORY_SIZE 128 * 1024 #define NUM_OBJECTS 128 //------------------------------------------------------------------------------ // CONSTANTS AND TYPES //------------------------------------------------------------------------------ union VALUE { int value; double d; char buffer[MEMORY_SIZE / NUM_OBJECTS]; }; typedef union VALUE Value; //------------------------------------------------------------------------------ // PROTOTYPES //------------------------------------------------------------------------------ static Ref testInsertion( const int size, boolean expSuccess ); static void testGet( const Ref ref, boolean expSuccess ); //------------------------------------------------------------------------------ // VARIABLES //------------------------------------------------------------------------------ static int numFailure = 0; static int numSuccess = 0; static int numTests = 0; //------------------------------------------------------------------------------ // FUNCTIONS //------------------------------------------------------------------------------ int main( int argc, char * argv[] ) { Ref ref[NUM_OBJECTS + 1] = { NULL_REF }; if( initialize( MEMORY_SIZE ) ) { for( int i = 0; i < NUM_OBJECTS; ++i ) { ref[i] = testInsertion( sizeof( Value ), true ); testGet( ref[i], true ); } dump( ); removeRef( ref[0] ); // just to have different output ref[NUM_OBJECTS] = testInsertion( sizeof( Value ) * 2, false ); //dump( ); destroy( ); //dump( ); } else { printf( "Failed to initialize the object manager!!\n" ); } printf( "Number of tests: %d\n", numTests ); printf( "Success tests: %d\n", numSuccess ); printf( "Failed tests: %d\n", numFailure ); return EXIT_SUCCESS; } static Ref testInsertion( const int size, boolean expSuccess ) { Ref ref = insert( size ); if( (expSuccess && NULL_REF != ref) || (!expSuccess && NULL_REF == ref) ) { numSuccess++; } else { numFailure++; } numTests++; return ref; } static void testGet( const Ref ref, boolean expSuccess ) { void * ptr = get( ref ); if( (expSuccess && NULL != ptr) || (!expSuccess && NULL == ptr) ) { numSuccess++; } else { numFailure++; } numTests++; }