include/Tests/RendererTests.hpp

Go to the documentation of this file.
00001 #ifndef hpp_RendererTests_hpp
00002 #define hpp_RendererTests_hpp
00003 
00004 // We need renderer declaration
00005 #include "../HTMLRenderer/GenericRenderer.hpp"
00006 // We need test vectors
00007 #include "TestVectors.hpp"
00008 // We need parser declaration
00009 #include "../HTMLParser/Parser.hpp"
00010 
00011 
00012 namespace Tests
00013 {
00014     struct RendererTest
00015     {
00016         // Create an node allocator if not done yet (this can as simple as the "new" based allocator)
00017         HTML::Elements::Allocators::SimpleHeap xElementAllocator;
00018         HTML::Renderer::Allocators::SimpleHeap xBoxAllocator;
00019         Stream::InputFileStream xFS;
00020         // Create the parser now 
00021         HTML::Parser * xParser;
00022 
00023         HTML::Renderer::Mapper * xMapper;
00024 
00025         bool testParserCreation()
00026         {
00027             xParser = new HTML::Parser(xFS, xElementAllocator, HTML::Parser::InstantParsing, HTML::LooseDTD);
00028             if (!xParser) return false;
00029             // Get the last error
00030             const HTML::Parser::ParsingError & xError = xParser->getLastParsingError();
00031        
00032             return !xError.isError();
00033         }
00034 
00035         bool testRenderer()
00036         {
00037             if (!xParser) return false;
00038             // Get the DOM tree
00039             HTML::DOMTree & tree = xParser->getDOMTree();
00040             xMapper = new HTML::Renderer::Mapper(tree.getRootNode()->getData(), xBoxAllocator, 640, 480, 0);
00041             if (!xMapper) return false;
00042 
00043             // Generate the box hierarchy
00044             if (!xMapper->generateBoxHierarchy()) return false;
00045             // Check the box hierarchy
00046             const HTML::Renderer::BoxHierarchy * root = xMapper->getRootHierarchy();
00047             if (!root) return false;
00048 
00049             // Dump the hierarchy to the output console
00050             Bstrlib::String result;
00051             int level = 0;
00052 
00053             while (root)
00054             {
00055                 for (int i = 0; i < level; i++)
00056                     result += "    ";
00057 
00058                 result += HTML::allowedElements[(int)root->tagType - 1].name;
00059                 result += " [";
00060                 result += Strings::convert(root->ClassAttribute);
00061                 result += "]";
00062                 result += "\r\n";
00063                 if (root->child)
00064                 {
00065                     root = root->child;
00066                     level ++;
00067                 }
00068                 else if (root->next)
00069                     root = root->next;
00070                 else 
00071                 {
00072                     while (root)
00073                     {
00074                         level --;
00075                         if (root->parent && root->parent->next)
00076                         {    root = root->parent->next; break; }
00077                         root = root->parent;
00078                     }
00079                 }
00080             }
00081 
00082             for (int i = 0; i < result.getLength(); i+=1023)
00083             {
00084                 DebugText((const char*)result.midString(i, 1023));
00085                 Sleep(40);
00086             }
00087             return true;
00088         }
00089 
00090         RendererTest() : xFS("../../../testFiles/docs.htm"), xParser(0), xMapper(0) {}
00091         ~RendererTest() { delete xMapper; delete xParser; }
00092     };
00093 
00094     void createRendererTests(Test::Vector & xVector, Bstrlib::String & results)
00095     {
00096         typedef Bstrlib::String String; 
00097         xVector.addUnitToTest(Test::MakeLineDelimiter("Renderer testing"));
00098         {
00099             RendererTest xRT;
00100             xVector.addUnitToTest(Test::MakeUnitTest(MakeTestName( "Creating parser" ), xRT, &RendererTest::testParserCreation));
00101             xVector.addUnitToTest(Test::MakeUnitTest(MakeTestName( "Creating renderer" ), xRT, &RendererTest::testRenderer));
00102             xVector.testLastInsertedVectors(results);
00103         }
00104     }
00105 }
00106 
00107 
00108 #endif
00109 

(C) An X-Ryl669 project 2007

This document describes Unlimited Zooming Interface source code. UZI stands for Unlimited Zooming Interface, and source code license is