int main() { gDevices.RegisterDevice(new FileDevice("data", ".")); gDevices.RegisterDevice(new FileDevice("folder", ".\\TestFolder")); // Makes all output show up in debug output screen TraceStream<char>::sHookStream(std::cout); TraceStream<wchar_t>::sHookStream(std::wcout); // Register classes for reflection ReflectionHost::sGetReflectionHost().RegisterClassType<Node>(); ReflectionHost::sGetReflectionHost().RegisterClassType<LeafNode>(); ReflectionHost::sGetReflectionHost().RegisterClassType<BranchNode>(); Array<Node*> nodes; int idx = 0; for (int x = 0; x < 10; x++) { Node* node = new LeafNode(String("leaf_text") + gToString(x)); node->mLocation = String("data@outputfile") + gToString(gRand() % 4) + String(".txt"); node->mName = String("L") + gToString(idx++); nodes.Append(node); } idx = 0; for (int x = 0; x < 20; x++) { BranchNode* branch = new BranchNode(String("branch_text") + gToString(x)); branch->mLocation = String("data@outputfile") + gToString(gRand() % 4) + String(".txt"); branch->mName = String("B") + gToString(idx++); branch->mChildA = (Node*) nodes[gRand()%nodes.GetLength()]; branch->mChildB = (Node*) nodes[gRand()%nodes.GetLength()]; nodes.Append(branch); } ObjectCollection oc_write; for (Node* n : nodes) { oc_write.AddObject(n); } oc_write.SaveToStreams(); ObjectCollection oc_read; oc_read.LoadFromStream("*****@*****.**"); std::cout << "WRITE TO DISK" << std::endl; for (TypedCompoundPointer tc : oc_write.GetObjects()) { ((Node*)tc.mPointer)->Print(0); } std::cout << "READ FROM DISK" << std::endl; for (TypedCompoundPointer tc : oc_read.GetObjects()) { ((Node*)tc.mPointer)->Print(0); } // //TestClass* to = oc_read.FindObject<TestClass>("TestObject0"); //TestClass* eo = oc_read.FindObject<TestClass>("ExternObject0"); RefPtr<Poop> poop1 = new Poop(); std::cout << "1" << std::endl; RefPtr<Poop> poop2 = poop1; std::cout << "2" << std::endl; poop1 = nullptr; std::cout << "3" << std::endl; poop2 = nullptr; std::cout << "4" << std::endl; return 0; }
/////////////////////////////////////////////////////////////////////////////// // runOne: Run a single test case /////////////////////////////////////////////////////////////////////////////// void MakeCurrentTest::runOne(MakeCurrentResult& r, Window& w) { DrawingSurfaceConfig& config = *(r.config); WindowSystem& ws = env->winSys; // The rendering contexts to be used: vector<RenderingContext*> rcs; RandomBitsDouble rRand(config.r, 712105); RandomBitsDouble gRand(config.g, 63230); RandomBitsDouble bRand(config.b, 912167); // Create rendering contexts to be used with the test window. // Note that the first context (at index 0) is always the // null context. rcs.push_back(0); r.descriptions.push_back("Null context"); ws.makeCurrent(); r.testSequence.push_back(static_cast<int>(rcs.size()) - 1); rcs.push_back(new RenderingContext(env->winSys, config, 0, true)); r.descriptions.push_back("Direct-rendering context"); ws.makeCurrent(*rcs.back(), w); r.testSequence.push_back(static_cast<int>(rcs.size()) - 1); glDisable(GL_DITHER); glClearColor(rRand.next(), gRand.next(), bRand.next(), 1.0); if (!makeCurrentOK(config)) goto failed; rcs.push_back(new RenderingContext(env->winSys, config, 0, false)); r.descriptions.push_back("Indirect-rendering context"); ws.makeCurrent(*rcs.back(), w); r.testSequence.push_back(static_cast<int>(rcs.size()) - 1); glDisable(GL_DITHER); glClearColor(rRand.next(), gRand.next(), bRand.next(), 1.0); if (!makeCurrentOK(config)) goto failed; // Now run through all the pairs of rendering contexts, making // them current in sequence and checking that rendering looks // correct. Don't worry about the redundant sequences; we want // to check those, too! int i; for (i = 0; i < static_cast<int>(rcs.size()); ++i) for (int j = 0; j < static_cast<int>(rcs.size()); ++j) { r.testSequence.push_back(i); if (rcs[i] == 0) ws.makeCurrent(); else { ws.makeCurrent(*rcs[i], w); if (!makeCurrentOK(config)) goto failed; } r.testSequence.push_back(j); if (rcs[j] == 0) ws.makeCurrent(); else { ws.makeCurrent(*rcs[j], w); if (!makeCurrentOK(config)) goto failed; } } r.pass = true; goto cleanup; failed: r.pass = false; cleanup: for (i = 0; i < static_cast<int>(rcs.size()); ++i) if (rcs[i]) { // We need to make sure that no GL commands are // pending when the window is destroyed, or we // risk a GLXBadCurrentWindow error at some // indeterminate time in the future when // glXMakeCurrent() is executed. // In theory, if glReadPixels() is the last // command executed by a test, then an implicit // flush has occurred, and the command queue is // empty. In practice, we have to protect // against the possibility that the implicit // flush is not enough to avoid the error. ws.makeCurrent(*rcs[i], w); glFinish(); ws.makeCurrent(); delete rcs[i]; } } // MakeCurrentTest::runOne
void ReadPixSanityTest::checkRGBA(ReadPixSanityResult& r, Window& w) { DrawingSurfaceConfig& config = *r.config; RandomBitsDouble rRand(config.r, 1066); RandomBitsDouble gRand(config.g, 1492); RandomBitsDouble bRand(config.b, 1776); RandomBitsDouble aRand((config.a? config.a: 1), 1789); int thresh = 1; r.passRGBA = true; r.errRGBA = 0.0; for (int i = 0; i < 100 && r.passRGBA; ++i) { // Generate a random color and use it to clear the color buffer: float expected[4]; expected[0] = rRand.next(); expected[1] = gRand.next(); expected[2] = bRand.next(); expected[3] = aRand.next(); glClearColor(expected[0],expected[1],expected[2],expected[3]); glClear(GL_COLOR_BUFFER_BIT); // If the color buffer doesn't have an alpha channel, then // the spec requires the readback value to be 1.0: if (!config.a) expected[3] = 1.0; // Read the buffer: GLfloat buf[READPIX_SANITY_WIN_SIZE][READPIX_SANITY_WIN_SIZE][4]; glReadPixels(0, 0, READPIX_SANITY_WIN_SIZE, READPIX_SANITY_WIN_SIZE, GL_RGBA, GL_FLOAT, buf); // Now compute the error for each pixel, and record the // worst one we find: for (int y = 0; y < READPIX_SANITY_WIN_SIZE; ++y) for (int x = 0; x < READPIX_SANITY_WIN_SIZE; ++x) { GLfloat dr = abs(buf[y][x][0] - expected[0]); GLfloat dg = abs(buf[y][x][1] - expected[1]); GLfloat db = abs(buf[y][x][2] - expected[2]); GLfloat da = abs(buf[y][x][3] - expected[3]); double err = max(ErrorBits(dr, config.r), max(ErrorBits(dg, config.g), max(ErrorBits(db, config.b), ErrorBits(da, config.a? config.a: thresh+1)))); // The "thresh+1" fudge above is // needed to force the error to // be greater than the threshold // in the case where there is no // alpha channel. Without it the // error would be just equal to // the threshold, and the test // would spuriously pass. if (err > r.errRGBA) { r.xRGBA = x; r.yRGBA = y; r.errRGBA = err; for (int j = 0; j < 4; ++j) { r.expectedRGBA[j] = expected[j]; r.actualRGBA[j] = buf[y][x][j]; } } } if (r.errRGBA > thresh) r.passRGBA = false; w.swap(); } } // ReadPixSanityTest::checkRGBA