lib/restream/test/test.cpp

Go to the documentation of this file.
00001 /*
00002  * test.cpp
00003  *
00004  * Copyright (C) 2011  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  * Test program for the restream library.  See restream.h
00008  */
00009 
00010 // includes --------------------------------------------------------------------
00011 #include <iostream>
00012 
00013 #include "perf/perf.h"
00014 #include "resources/resources.h"
00015 #include "restream/restream.h"
00016 
00017 
00018 
00019 ////////////////////////////////////////////////////////////////////////////////
00020 //
00021 //      static helper methods
00022 //
00023 ////////////////////////////////////////////////////////////////////////////////
00024 
00025 static void
00026 testPath
00027 (
00028 IN nstream::Manager * mgr,
00029 IN const char * path
00030 )
00031 {
00032         ASSERT(mgr, "null");
00033         ASSERT(path, "null");
00034 
00035         DPRINTF("Testing path: '%s'", path);
00036         smart_ptr<nstream::Entry> e = mgr->getEntry(path);
00037         ASSERT_THROW(e, "Failed to parse path: " << path);
00038 }
00039 
00040 
00041 
00042 static void
00043 doTest
00044 (
00045 void
00046 )
00047 {
00048         smart_ptr<nstream::Manager> mgr = nstream::getResourceStreamManager();
00049         ASSERT_THROW(mgr, "failed to create resource stream manager");
00050 
00051         // first iterate namespaces...
00052         DPRINTF("Iterating namespaces...");
00053         smart_ptr<nstream::Folder> root = mgr->getRoot();
00054         ASSERT_THROW(root, "failed to get root of resource streams");
00055         while (smart_ptr<nstream::Entry> e = root->getNextChild()) {
00056                 DPRINTF("  Child (namespace): '%s'", e->getName());
00057 
00058                 smart_ptr<nstream::Folder> f = e;
00059                 ASSERT_THROW(f, "failed to cast namespace entry to folder");
00060 
00061                 // now iterate through this namespace
00062                 DPRINTF("Iterating namespace '%s'", f->getName());
00063                 while (smart_ptr<nstream::Entry> n = f->getNextChild()) {
00064                         DPRINTF("  entry '%s'", n->getName());
00065                         smart_ptr<nstream::File> file = n;
00066                         ASSERT_THROW(file,
00067                             "failed to cast namespace child to file");
00068 
00069                         ASSERT_THROW(
00070                             getResourceSize(f->getName(), file->getName()) > 0,
00071                             "Failed to find resource information for this entry");
00072 
00073                         smart_ptr<nstream::Stream> stream = file->openStream();
00074                         ASSERT(stream, "failed to open stream?");
00075                 }
00076         }
00077 
00078         // try some edge cases
00079         DPRINTF("Trying odd path specifications...");
00080         testPath(mgr, "//namespaceA/");
00081         testPath(mgr, "/namespaceB/");
00082         testPath(mgr, "/namespaceB/test.jpg.txt");
00083         testPath(mgr, "namespaceB/");
00084 }
00085 
00086 
00087 
00088 ////////////////////////////////////////////////////////////////////////////////
00089 //
00090 //      entry point
00091 //
00092 ////////////////////////////////////////////////////////////////////////////////
00093 
00094 int
00095 main
00096 (
00097 IN int argc,
00098 IN const char * argv[]
00099 )
00100 {
00101         try {
00102                 perf::Timer timer("overall timer");
00103                 doTest();
00104         } catch (std::exception& e) {
00105                 DPRINTF("Exception!  %s", e.what());
00106                 return 1;
00107         }
00108 
00109         // all done
00110         perf::dumpTimingSummary(std::cout);
00111         return 0;
00112 }
00113