Changeset 122

Show
Ignore:
Timestamp:
04/26/06 16:32:51 (2 years ago)
Author:
jordi
Message:

Now all tests pass. It turns out that I used usleep(2) believing that it was in milliseconds instead of microseconds, so the time sleeping was too short. Also, the PDFDocumentTest was deleting the page in the renderPage() method, leading to a double delete.

Location:
trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/IDocument.cxx

    r121 r122  
    1717 
    1818#include <config.h> 
     19#include <string.h> 
    1920#include "epdfview.h" 
    2021 
     
    143144        PageRequest *request = (PageRequest *)g_async_queue_pop (renderQueue); 
    144145        G_LOCK (rendering); 
    145         if ( 0 < request->pageNum ) 
    146         { 
    147             if ( NULL != request->document ) 
    148             { 
    149                 request->page = request->document->renderPage (request->pageNum); 
    150             } 
    151             request->done = TRUE; 
    152         } 
    153         else if ( -1 == request->pageNum ) 
     146        if ( -1 == request->pageNum ) 
    154147        { 
    155148            delete request; 
     
    158151        else 
    159152        { 
     153            if ( 0 < request->pageNum ) 
     154            { 
     155                request->page =  
     156                    request->document->renderPage (request->pageNum); 
     157            } 
    160158            request->done = TRUE; 
    161159        } 
     
    215213    // thread that we are done. 
    216214    PageRequest *request = new PageRequest; 
     215    memset (request, 0, sizeof (PageRequest)); 
    217216    request->pageNum = -1; 
    218217    g_async_queue_unref (m_RenderQueue); 
     
    680679IDocument::getCurrentPage () 
    681680{ 
    682     GList *cache = g_list_first (m_PageCache); 
    683681    PageRequest *request = NULL; 
    684     while ( NULL != cache && NULL == request ) 
     682    for ( GList *cache = g_list_first (m_PageCache) ; 
     683          NULL != cache && NULL == request ; 
     684          cache = g_list_next (cache) ) 
    685685    { 
    686686        PageRequest *tmpRequest = (PageRequest *)cache->data; 
     
    689689            request = tmpRequest; 
    690690        } 
    691         cache = g_list_next (cache); 
    692691    } 
    693692 
    694693    if ( NULL == request ) 
     694    { 
    695695        return NULL; 
    696  
     696    } 
    697697    WAIT_REQUEST (request); 
    698  
    699698    return request->page; 
    700699} 
     
    10031002    // Check if the page is already on cache. 
    10041003    PageRequest *request = NULL; 
    1005     GList *cache = g_list_first (m_PageCache); 
    1006     while ( NULL != cache && NULL == request) 
     1004    for ( GList *cache = g_list_first (m_PageCache) ;  
     1005          NULL != cache && NULL == request ; 
     1006          cache = g_list_next (cache) ) 
    10071007    { 
    10081008        PageRequest *tmpRequest = (PageRequest *)cache->data; 
     
    10111011            request = tmpRequest; 
    10121012        } 
    1013         cache = g_list_next (cache); 
    10141013    } 
    10151014 
     
    10301029            PageRequest *oldestRequest = NULL; 
    10311030            guint32 oldestAge = G_MAXUINT32; 
    1032             for ( cache = g_list_first (m_PageCache) ; NULL != cache ; 
     1031            for ( GList *cache = g_list_first (m_PageCache) ; NULL != cache ; 
    10331032                  cache = g_list_next (cache) ) 
    10341033            { 
     
    10401039                } 
    10411040            } 
    1042             m_PageCache = g_list_remove (m_PageCache, oldestRequest); 
     1041            m_PageCache = g_list_remove_all (m_PageCache, oldestRequest); 
    10431042            WAIT_REQUEST (oldestRequest); 
    10441043            delete oldestRequest->page; 
     1044            oldestRequest->page = NULL; 
    10451045            delete oldestRequest; 
    10461046        } 
     
    10961096    { 
    10971097        PageRequest *request = (PageRequest *)cache->data; 
    1098         request->document = NULL; 
     1098        request->pageNum = 0; 
    10991099    } 
    11001100    G_UNLOCK (rendering); 
     
    11071107        WAIT_REQUEST (request); 
    11081108        delete request->page; 
     1109        request->page = NULL; 
    11091110        delete request; 
    11101111    } 
  • trunk/src/MainPter.cxx

    r120 r122  
    613613                        GError **error) 
    614614{ 
     615    g_assert ( NULL != m_Document && "The document is NULL."); 
     616 
    615617    // if fileName is NULL, then the user cancelled the operation. 
    616618    // I don't need to do anything in this case. I'm only interested when 
  • trunk/tests/DumbDocument.cxx

    r120 r122  
    3636DumbDocument::~DumbDocument () 
    3737{ 
     38    clearCache (); 
    3839    g_free (m_TestPassword); 
    3940} 
  • trunk/tests/MainPterTest.cxx

    r120 r122  
    2626CPPUNIT_TEST_SUITE_REGISTRATION (MainPterTest); 
    2727 
     28// Constants. 
     29static const gint SLEEP_TIME = 250000; 
     30 
    2831/// 
    2932/// @brief Sets up the environment for each test. 
     
    100103    m_MainPter->openFileActivated (); 
    101104    // Sleep to let the thread open the file. 
    102     usleep (500); 
     105    usleep (SLEEP_TIME); 
    103106    CPPUNIT_ASSERT_EQUAL (0,  
    104107            g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 
     
    122125    m_MainPter->openFileActivated (); 
    123126    // Sleep to let the thread open the file. 
    124     usleep (500); 
     127    usleep (SLEEP_TIME); 
    125128    CPPUNIT_ASSERT_EQUAL (0,  
    126129            g_ascii_strcasecmp ("Test PDF", m_View->getTitle ())); 
     
    153156    m_MainPter->openFileActivated (); 
    154157    // Sleep to let the thread open the file. 
    155     usleep (500); 
     158    usleep (SLEEP_TIME); 
    156159    CPPUNIT_ASSERT_EQUAL (0,  
    157160            g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); 
     
    186189    m_MainPter->openFileActivated (); 
    187190    // Sleep to let the thread open the file. 
    188     usleep (500); 
     191    usleep (SLEEP_TIME); 
    189192    CPPUNIT_ASSERT_EQUAL (0,  
    190193            g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); 
     
    221224    m_MainPter->openFileActivated (); 
    222225    // Sleep to let the thread open the file. 
    223     usleep (500); 
     226    usleep (SLEEP_TIME); 
    224227    CPPUNIT_ASSERT_EQUAL (0,  
    225228            g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); 
     
    256259    m_MainPter->openFileActivated (); 
    257260    // Sleep to let the thread open the file. 
    258     usleep (500); 
     261    usleep (SLEEP_TIME); 
    259262    CPPUNIT_ASSERT_EQUAL (0,  
    260263            g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); 
     
    291294    m_MainPter->openFileActivated (); 
    292295    // Sleep to let the thread open the file. 
    293     usleep (500); 
     296    usleep (SLEEP_TIME); 
    294297    CPPUNIT_ASSERT_EQUAL (0,  
    295298            g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 
     
    324327    m_MainPter->openFileActivated (); 
    325328    // Sleep to let the thread open the file. 
    326     usleep (500); 
     329    usleep (SLEEP_TIME); 
    327330    CPPUNIT_ASSERT (NULL == m_View->getLastOpenFileFolder ()); 
    328331 
     
    331334    m_MainPter->openFileActivated (); 
    332335    // Sleep to let the thread open the file. 
    333     usleep (500); 
     336    usleep (SLEEP_TIME); 
    334337    CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/tmp",  
    335338                                             m_View->getLastOpenFileFolder ())); 
     
    337340    m_MainPter->openFileActivated (); 
    338341    // Sleep to let the thread open the file. 
    339     usleep (500); 
     342    usleep (SLEEP_TIME); 
    340343    CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/usr",  
    341344                                             m_View->getLastOpenFileFolder ())); 
     
    355358    m_MainPter->openFileActivated (); 
    356359    // Sleep to let the thread open the file. 
    357     usleep (500); 
     360    usleep (SLEEP_TIME); 
    358361    // Check that sets the correct number of pages and the current page. 
    359362    CPPUNIT_ASSERT_EQUAL (4, m_View->getTotalPages ()); 
     
    437440    m_MainPter->openFileActivated (); 
    438441    // Sleep to let the thread open the file. 
    439     usleep (500); 
     442    usleep (SLEEP_TIME); 
    440443    // Check that sets the correct number of pages and the current page. 
    441444    CPPUNIT_ASSERT_EQUAL (4, m_View->getTotalPages ()); 
     
    518521    m_MainPter->openFileActivated (); 
    519522    // Sleep to let the thread open the file. 
    520     usleep (500); 
     523    usleep (SLEEP_TIME); 
    521524    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    522525    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     
    548551    m_MainPter->openFileActivated (); 
    549552    // Sleep to let the thread open the file. 
    550     usleep (500); 
     553    usleep (SLEEP_TIME); 
    551554    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    552555    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     
    589592    m_MainPter->openFileActivated (); 
    590593    // Sleep to let the thread open the file. 
    591     usleep (500); 
     594    usleep (SLEEP_TIME); 
    592595    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    593596    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 
     
    655658    m_MainPter->openFileActivated (); 
    656659    // Sleep to let the thread open the file. 
    657     usleep (500); 
     660    usleep (SLEEP_TIME); 
    658661    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    659662    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 
     
    720723    m_MainPter->openFileActivated (); 
    721724    // Sleep to let the thread open the file. 
    722     usleep (500); 
     725    usleep (SLEEP_TIME); 
    723726    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    724727    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 
     
    765768    m_MainPter->openFileActivated (); 
    766769    // Sleep to let the thread open the file. 
    767     usleep (500); 
     770    usleep (SLEEP_TIME); 
    768771    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    769772 
     
    779782    m_MainPter->reloadActivated (); 
    780783    // Sleep to let the thread open the file. 
    781     usleep (500); 
     784    usleep (SLEEP_TIME); 
    782785    CPPUNIT_ASSERT_EQUAL (0,  
    783786            g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 
     
    803806    m_MainPter->openFileActivated (); 
    804807    // Sleep to let the thread open the file. 
    805     usleep (500); 
     808    usleep (SLEEP_TIME); 
    806809    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    807810    CPPUNIT_ASSERT_EQUAL (0,  
     
    822825    m_MainPter->reloadActivated (); 
    823826    // Sleep to let the thread open the file. 
    824     usleep (500); 
     827    usleep (SLEEP_TIME); 
    825828    CPPUNIT_ASSERT_EQUAL (0,  
    826829            g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 
     
    847850    m_MainPter->openFileActivated (); 
    848851    // Sleep to let the thread open the file. 
    849     usleep (500); 
     852    usleep (SLEEP_TIME); 
    850853    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    851854    CPPUNIT_ASSERT_EQUAL (0,  
     
    868871    m_MainPter->reloadActivated (); 
    869872    // Sleep to let the thread open the file. 
    870     usleep (500); 
     873    usleep (SLEEP_TIME); 
    871874    CPPUNIT_ASSERT_EQUAL (0, 
    872875            g_ascii_strcasecmp("newpassword", m_Document->getPassword ())); 
     
    907910    m_MainPter->openFileActivated (); 
    908911    // Sleep to let the thread open the file. 
    909     usleep (500); 
     912    usleep (SLEEP_TIME); 
    910913    CPPUNIT_ASSERT (m_View->isShownSidebar ()); 
    911914    CPPUNIT_ASSERT (outline == m_View->getOutline ()); 
  • trunk/tests/PDFDocumentTest.cxx

    r120 r122  
    507507    CPPUNIT_ASSERT (0 != memcmp (testData, page->getData (), imageSize)); 
    508508    delete[] testData; 
    509     delete page; 
    510  
    511     g_free (testFile); 
    512 } 
     509 
     510    g_free (testFile); 
     511}