void ComponentTests::run() { coment::World world; coment::Entity e; Position* pos; Velocity* vel; // Create entity e = world.createEntity(); // Check entity doesn't have component before adding begintest("Checking entity doesn't have component yet"); endtest(world.getComponent<Position>(e) == NULL); // Add component to entity begintest("Adding position component to entity"); pos = world.addComponent<Position>(e); endtest(world.getComponent<Position>(e) != NULL); // Get component from entity begintest("Retrieve component from entity"); endtest(world.getComponent<Position>(e) == pos); // Add velocity component begintest("Adding second component"); vel = world.addComponent<Velocity>(e); endtest(vel != NULL); // Remove component from entity begintest("Remove velocity component"); world.removeComponent<Velocity>(e); endtest(world.getComponent<Velocity>(e) == NULL && world.getComponent<Position>(e) != NULL); // Remove all components from entity begintest("Remove all components from entity"); world.addComponent<Velocity>(e); world.loopStart(); world.removeComponents(e); endtest(world.getComponent<Velocity>(e) == NULL && world.getComponent<Position>(e) == NULL); return; }
void InitScene (void) { GLint params[1]; const char *tab[2]; /* * GL should silently ignore calls that delete object 0. */ begintest (TT_GETERROR_NOERROR, "glDeleteObject(0)"); glDeleteObjectARB (0); endtest (); /* * GL generates an error on invalid object handle. */ begintest (TT_GETERROR_INVALIDVALUE, "Pass invalid non-zero object handle"); glDeleteObjectARB (find_invalid_handle ()); endtest (); glUseProgramObjectARB (find_invalid_handle ()); endtest (); /* * Create object. GL should return unique non-zero values. */ begintest (TT_PARAM1_NONZERO, "Create object"); vert = glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB); endtest1 (vert); frag = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB); endtest1 (frag); prog = glCreateProgramObjectARB (); endtest1 (prog); endtest1 (vert != frag && frag != prog && prog != vert); /* * Link empty program. */ begintest (TT_PARAM1_NONZERO, "Link empty program"); glLinkProgramARB (prog); endtest1 (CheckObjectStatus (prog)); /* * Use empty program object. Empty program objects are valid. */ begintest (TT_GETERROR_NOERROR, "Use empty program object"); glUseProgramObjectARB (prog); endtest (); /* * Attach invalid object handles. Program object 0 should not be accepted. */ begintest (TT_GETERROR_INVALIDVALUE, "Attach invalid object handle"); glAttachObjectARB (0, find_invalid_handle ()); endtest (); glAttachObjectARB (0, frag); endtest (); glAttachObjectARB (find_invalid_handle (), find_invalid_handle ()); endtest (); glAttachObjectARB (find_invalid_handle (), frag); endtest (); glAttachObjectARB (prog, find_invalid_handle ()); endtest (); /* * Attach valid object handles with wrong semantics. */ begintest (TT_GETERROR_INVALIDOPERATION, "Attach object badly"); glAttachObjectARB (vert, frag); endtest (); glAttachObjectARB (vert, prog); endtest (); glAttachObjectARB (prog, prog); endtest (); /* * Detach non-attached object. */ begintest (TT_GETERROR_INVALIDOPERATION, "Detach non-attached object"); glDetachObjectARB (prog, vert); endtest (); glDetachObjectARB (prog, frag); endtest (); /* * Attach shader. */ begintest (TT_GETERROR_NOERROR, "Attach shader to program object"); glAttachObjectARB (prog, vert); endtest (); glAttachObjectARB (prog, frag); endtest (); /* * Attach object twice. */ begintest (TT_GETERROR_INVALIDOPERATION, "Attach object twice"); glAttachObjectARB (prog, vert); endtest (); glAttachObjectARB (prog, frag); endtest (); /* * Detach attached object. */ begintest (TT_GETERROR_NOERROR, "Detach attached object"); glDetachObjectARB (prog, vert); endtest (); glDetachObjectARB (prog, frag); endtest (); /* * Attach shader again. */ begintest (TT_GETERROR_NOERROR, "Attach shader again"); glAttachObjectARB (prog, vert); endtest (); glAttachObjectARB (prog, frag); endtest (); /* * Delete attached object. */ begintest (TT_GETERROR_NOERROR, "Delete attached object"); glDeleteObjectARB (vert); endtest (); glDeleteObjectARB (frag); endtest (); /* * Query delete status. It should return TRUE. Object handles are still valid * as they are referenced by program object container. */ begintest (TT_PARAM1_NONZERO, "Query delete status"); glGetObjectParameterivARB (vert, GL_OBJECT_DELETE_STATUS_ARB, params); endtest1 (params[0]); glGetObjectParameterivARB (frag, GL_OBJECT_DELETE_STATUS_ARB, params); endtest1 (params[0]); /* * Delete already deleted attached object. The behaviour is undefined, but we * check for no errors. The object still exists, so the handle value is okay. * In other words, these calls should be silently ignored by GL. */ begintest (TT_GETERROR_NOERROR, "Delete already deleted attached object"); glDeleteObjectARB (vert); endtest (); glDeleteObjectARB (frag); endtest (); /* * Compile shader source with syntax error. */ begintest (TT_PARAM1_ZERO, "Compile shader source with syntax error"); glShaderSourceARB (vert, 1, &invsynvertsrc, NULL); glCompileShaderARB (vert); endtest1 (CheckObjectStatus (vert)); glShaderSourceARB (frag, 1, &invsynfragsrc, NULL); glCompileShaderARB (frag); endtest1 (CheckObjectStatus (frag)); /* * Compile shader source with semantic error. */ begintest (TT_PARAM1_ZERO, "Compile shader source with semantic error"); glShaderSourceARB (vert, 1, &invsemvertsrc, NULL); glCompileShaderARB (vert); endtest1 (CheckObjectStatus (vert)); glShaderSourceARB (frag, 1, &invsemfragsrc, NULL); glCompileShaderARB (frag); endtest1 (CheckObjectStatus (frag)); /* * Link ill-formed vertex-fragment program. */ begintest (TT_PARAM1_ZERO, "Link ill-formed vertex-fragment program"); glLinkProgramARB (prog); endtest1 (CheckObjectStatus (prog)); /* * Use badly linked program object. */ begintest (TT_GETERROR_INVALIDOPERATION, "Use badly linked program object"); glUseProgramObjectARB (prog); endtest (); /* * Compile well-formed shader source. Check if multi-string sources can be handled. */ begintest (TT_PARAM1_NONZERO, "Compile well-formed shader source"); tab[0] = uniforms; tab[1] = validvertsrc; glShaderSourceARB (vert, 2, tab, NULL); glCompileShaderARB (vert); endtest1 (CheckObjectStatus (vert)); tab[0] = uniforms; tab[1] = validfragsrc; glShaderSourceARB (frag, 2, tab, NULL); glCompileShaderARB (frag); endtest1 (CheckObjectStatus (frag)); /* * Link vertex-fragment program. */ begintest (TT_PARAM1_NONZERO, "Link vertex-fragment program"); glLinkProgramARB (prog); endtest1 (CheckObjectStatus (prog)); /* * Use valid linked program object. */ begintest (TT_GETERROR_NOERROR, "Use linked program object"); glUseProgramObjectARB (prog); endtest (); /* * Get current program. */ begintest (TT_PARAM1_NONZERO, "Get current program"); endtest1 (glGetHandleARB (GL_PROGRAM_OBJECT_ARB) == prog); /* * Use 0 program object. */ begintest (TT_GETERROR_NOERROR, "Use 0 program object"); glUseProgramObjectARB (0); endtest (); /* * Query uniform location. Uniforms with gl_ prefix cannot be queried. */ begintest (TT_PARAM1_NONZERO, "Query uniform location"); endtest1 (glGetUniformLocationARB (prog, "gl_ModelViewMatrix") == -1); endtest1 (glGetUniformLocationARB (prog, "UniformThatDoesNotExist") == -1); endtest1 (glGetUniformLocationARB (prog, "") == -1); endtest1 (glGetUniformLocationARB (prog, "CommonUniform") != -1); endtest1 (glGetUniformLocationARB (prog, "VertexUniform") != -1); endtest1 (glGetUniformLocationARB (prog, "FragmentUniform") != -1); /* * Query attrib location. Attribs with gl_ prefix cannot be queried. * When gl_Vertex is used, none of the generic attribs can have index 0. */ begintest (TT_PARAM1_NONZERO, "Query attrib location"); endtest1 (glGetAttribLocationARB (prog, "gl_Vertex") == -1); endtest1 (glGetAttribLocationARB (prog, "AttribThatDoesNotExist") == -1); endtest1 (glGetAttribLocationARB (prog, "") == -1); endtest1 (glGetAttribLocationARB (prog, "FirstAttrib") > 0); endtest1 (glGetAttribLocationARB (prog, "SecondAttrib") > 0); /* * Bind attrib locations, link and check if locations are correct. */ begintest (TT_PARAM1_NONZERO, "Bind attrib location #1"); glBindAttribLocationARB (prog, 1, "FirstAttrib"); glBindAttribLocationARB (prog, 2, "SecondAttrib"); glLinkProgramARB (prog); endtest1 (CheckObjectStatus (prog)); endtest1 (glGetAttribLocationARB (prog, "FirstAttrib") == 1); endtest1 (glGetAttribLocationARB (prog, "SecondAttrib") == 2); /* * Bind attrib locations in different order. Link and check if locations are correct. */ begintest (TT_PARAM1_NONZERO, "Bind attrib location #2"); glBindAttribLocationARB (prog, 1, "SecondAttrib"); glBindAttribLocationARB (prog, 2, "FirstAttrib"); glLinkProgramARB (prog); endtest1 (CheckObjectStatus (prog)); endtest1 (glGetAttribLocationARB (prog, "SecondAttrib") == 1); endtest1 (glGetAttribLocationARB (prog, "FirstAttrib") == 2); /* * Detach deleted object. */ begintest (TT_GETERROR_NOERROR, "Detach deleted object"); glDetachObjectARB (prog, vert); endtest (); glDetachObjectARB (prog, frag); endtest (); /* * Delete deleted detached object. */ begintest (TT_GETERROR_INVALIDVALUE, "Delete deleted detached object"); glDeleteObjectARB (vert); endtest (); glDeleteObjectARB (frag); endtest (); exit (0); }
void FileTests::run() { bool success = false; // Generate random strings char* filename = generateString(20); char* randomString = generateString(100); begintest("Create file with random name: " << filename); File file(filename); endtest(file.isOpen()); begintest("Write 100 bytes to file"); int bytesWritten = file.write(randomString); endtest(bytesWritten == 100); begintest("Close file"); file.close(); endtest(!file.isOpen()); begintest("Open same file by default constructor + call to open()"); File file2; file2.open(filename, false); endtest(file2.isOpen()); begintest("Delete file and check it doesn't exist"); file2.deleteFile(); endtest(!File::exists(filename)); // Generate new filename and string ali::dealloc(filename); ali::dealloc(randomString); filename = generateString(20); randomString = generateString(200); begintest("Write to file and then read it again"); success = false; // Write to a file file.open(filename); file.write(randomString); file.close(); file.open(filename); // Allocate memory for buffer int read = 0; char* buffer = (char*)ali::alloc(file.getLength()+1); // If read more than 0 bytes if ((read = file.read(buffer)) > 0) { // If read string is identical to written string, success = true success = (strcmp(buffer, randomString) == 0); } // Clean up test ali::dealloc(buffer); file.deleteFile(); endtest(success); // Clean up files file.close(); file2.close(); // Clean up memory ali::dealloc(filename); ali::dealloc(randomString); }
void SystemTests::run() { const int INITIAL_X = 50; const int INITIAL_Y = 50; const int INITIAL_VX = 50; const int INITIAL_VY = 50; const int WORLD_DELTA = 15; int updates = 0; coment::World world; coment::Entity e; Position* pos; Velocity* vel; // Systems MovementSystem movementSystem; // Set world delta world.setDelta(WORLD_DELTA); // Check boolean event flags are set correctly begintest("Checking boolean flags are set to false"); endtest(movementSystem.noEventsCalled()); // Register system and check if registered is called begintest("Registering system and checking if onRegistered is called"); world.registerSystem(movementSystem); endtest(movementSystem.onRegisteredCalled()); // Create entity e = world.createEntity(); pos = world.addComponent<Position>(e); vel = world.addComponent<Velocity>(e); // Initialise components pos->x = INITIAL_X; pos->y = INITIAL_Y; vel->x = INITIAL_VX; vel->y = INITIAL_VY; // Run tests begintest("Run one update (using World::update) and check entity is updated"); world.loopStart(); world.update(); updates++; endtest(((int)(pos->x) == INITIAL_X + INITIAL_VX * WORLD_DELTA * updates) && ((int)(pos->y) == INITIAL_X + INITIAL_VY * WORLD_DELTA * updates) && movementSystem.onFirstUpdateCalled() && movementSystem.onAddedCalled()); begintest("Add component back and check that entity gets updated"); updates = 0; pos = world.addComponent<Position>(e); world.loopStart(); movementSystem.update(); updates++; endtest(((int)(pos->x) == 0 + INITIAL_VX * WORLD_DELTA * updates) && ((int)(pos->y) == 0 + INITIAL_VY * WORLD_DELTA * updates)); begintest("Remove all components and check that entity doesn't get updated"); world.removeComponents(e); world.loopStart(); movementSystem.update(); endtest(((int)(pos->x) == 0 + INITIAL_VX * WORLD_DELTA * updates) && ((int)(pos->y) == 0 + INITIAL_VY * WORLD_DELTA * updates) && movementSystem.onRemovedCalled()); return; }