Changeset 8227 for branches

Show
Ignore:
Timestamp:
18/11/11 14:24:12 (6 months ago)
Author:
westram
Message:
  • extracted ED4_foldable from ED4_window
    • enables separate tests
    • added tests
      • use multiple folding lines
      • document wrong behavior (as in [8201])
Location:
branches/e4fix/EDIT4
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • branches/e4fix/EDIT4/ED4_manager.cxx

    r8201 r8227  
    998998 
    999999        int x1, y1, x2, y2; 
    1000         ED4_folding_line *flv, *flh; 
    10011000        ED4_window& win = *current_ed4w(); 
    10021001        int old_last_window_reached = last_window_reached; 
     
    10041003        last_window_reached = 0; 
    10051004        x1 = area_rect.l; 
    1006         for (flv = win.vertical_fl; ; flv = flv->next) { 
     1005        for (const ED4_folding_line *flv = win.get_vertical_folding(); ; flv = flv->next) { 
    10071006            int lastColumn = 0; 
    10081007 
     
    10231022 
    10241023            y1 = area_rect.t; 
    1025             for (flh = win.horizontal_fl; ; flh = flh->next) { 
     1024            for (const ED4_folding_line *flh = win.get_horizontal_folding(); ; flh = flh->next) { 
    10261025                int lastRow = 0; 
    10271026 
  • branches/e4fix/EDIT4/ED4_root.cxx

    r8202 r8227  
    104104 
    105105 
    106 void ED4_window::win_to_world_coords(AW_pos *xPtr, AW_pos *yPtr) { 
     106void ED4_foldable::win_to_world_coords(AW_pos *xPtr, AW_pos *yPtr) { 
    107107    // calculates transformation from window to world coordinates in a given window 
    108108    const AW_pos x = *xPtr; 
     
    136136} 
    137137 
    138 void ED4_window::world_to_win_coords(AW_pos *xPtr, AW_pos *yPtr) { 
     138void ED4_foldable::world_to_win_coords(AW_pos *xPtr, AW_pos *yPtr) { 
    139139    // calculates transformation from world to window coordinates in a given window 
    140140    const AW_pos x = *xPtr; 
     
    167167    *yPtr = temp_y; 
    168168} 
     169 
     170// -------------------------------------------------------------------------------- 
     171 
     172#ifdef UNIT_TESTS 
     173#ifndef TEST_UNIT_H 
     174#include <test_unit.h> 
     175#endif 
     176 
     177static arb_test::match_expectation correct_win2world_calculation(ED4_foldable& foldable, int xwin_org, int ywin_org, int xwrld_expd, int ywrld_expd) { 
     178    using namespace arb_test; 
     179    match_expectation precondition(all().of(that(xwrld_expd).more_or_equal(xwin_org), 
     180                                            that(ywrld_expd).more_or_equal(ywin_org))); 
     181 
     182    AW_pos xwrld_calc = xwin_org; 
     183    AW_pos ywrld_calc = ywin_org; 
     184    foldable.win_to_world_coords(&xwrld_calc, &ywrld_calc); 
     185 
     186    match_expectation win_2_world_conversion(all().of(that(xwrld_calc).equals(xwrld_expd), 
     187                                                      that(ywrld_calc).equals(ywrld_expd))); 
     188 
     189    AW_pos xwin_back = xwrld_calc; 
     190    AW_pos ywin_back = ywrld_calc; 
     191    foldable.world_to_win_coords(&xwin_back, &ywin_back); 
     192     
     193    match_expectation world_back2_win_conversion(all().of(that(xwin_back).equals(xwin_org), 
     194                                                          that(ywin_back).equals(ywin_org))); 
     195 
     196    return all().of(precondition, win_2_world_conversion, world_back2_win_conversion); 
     197} 
     198 
     199#define TEST_ASSERT_WIN_UNFOLDED(xwi,ywi)            TEST_EXPECT(correct_win2world_calculation(foldable, xwi, ywi, xwi, ywi)) 
     200#define TEST_ASSERT_WIN_WORLD_FOLDING(xwi,ywi,fx,fy) TEST_EXPECT(correct_win2world_calculation(foldable, xwi, ywi, (xwi)+(fx), (ywi)+(fy))) 
     201 
     202#define TEST_ASSERT_WIN_WORLD_FOLDING__BROKEN(xwi,ywi,fx,fy)        TEST_EXPECT__BROKEN(correct_win2world_calculation(foldable, xwi, ywi, (xwi)+(fx), (ywi)+(fy))) 
     203#define TEST_ASSERT_WIN_WORLD_FOLDING__BROKENIF(when,xwi,ywi,fx,fy) TEST_EXPECT__BROKENIF(when, correct_win2world_calculation(foldable, xwi, ywi, (xwi)+(fx), (ywi)+(fy))) 
     204 
     205void TEST_win_2_world() { 
     206    ED4_foldable foldable; 
     207 
     208    ED4_folding_line *hor100 = foldable.insert_folding_line(0, 100, INFINITE, 0, NULL, ED4_P_HORIZONTAL); 
     209    ED4_folding_line *ver200 = foldable.insert_folding_line(200, 0, INFINITE, 0, NULL, ED4_P_VERTICAL); 
     210 
     211    ED4_folding_line *hor200 = foldable.insert_folding_line(0, 200, 300, 0, NULL, ED4_P_HORIZONTAL); 
     212    ED4_folding_line *ver300 = foldable.insert_folding_line(300, 100, 200, 0, NULL, ED4_P_VERTICAL); 
     213 
     214    // nothing folded yet 
     215     
     216    TEST_ASSERT_WIN_UNFOLDED(100, 50); 
     217    TEST_ASSERT_WIN_UNFOLDED(250, 50); 
     218    TEST_ASSERT_WIN_UNFOLDED(400, 50); 
     219 
     220    TEST_ASSERT_WIN_UNFOLDED(100, 150); 
     221    TEST_ASSERT_WIN_UNFOLDED(250, 150); 
     222    TEST_ASSERT_WIN_UNFOLDED(400, 150); 
     223 
     224    TEST_ASSERT_WIN_UNFOLDED(100, 250); 
     225    TEST_ASSERT_WIN_UNFOLDED(250, 250); 
     226    TEST_ASSERT_WIN_UNFOLDED(400, 250); 
     227 
     228    TEST_ASSERT_WIN_UNFOLDED(100, 350); 
     229    TEST_ASSERT_WIN_UNFOLDED(250, 350); 
     230    TEST_ASSERT_WIN_UNFOLDED(400, 350); 
     231 
     232    for (int FACTOR = 1; FACTOR <= 10; FACTOR ++) { 
     233        TEST_ANNOTATE_ASSERT(GBS_global_string("FACTOR=%i", FACTOR)); 
     234        int H1 = FACTOR* 10; 
     235        int H2 = FACTOR* 40; 
     236        int V1 = FACTOR* 20; 
     237        int V2 = FACTOR* 80; 
     238 
     239        hor100->dimension = H1; 
     240        hor200->dimension = H2; 
     241        ver200->dimension = V1; 
     242        ver300->dimension = V2; 
     243 
     244        TEST_ASSERT_WIN_UNFOLDED(100, 50); // always in unfolded range 
     245        TEST_ASSERT_WIN_WORLD_FOLDING(250, 50, V1, 0); 
     246        TEST_ASSERT_WIN_WORLD_FOLDING(400, 50, V1, 0); 
     247 
     248        TEST_ASSERT_WIN_WORLD_FOLDING__BROKENIF(FACTOR >= 5, 100, 150, 0,     H1); 
     249        TEST_ASSERT_WIN_WORLD_FOLDING__BROKENIF(FACTOR >= 3, 250, 150, V1,    H1); 
     250        TEST_ASSERT_WIN_WORLD_FOLDING(400, 150, V1+V2, H1); 
     251        TEST_ASSERT_WIN_WORLD_FOLDING__BROKENIF(FACTOR >= 3, 250, 250, V1,    H1+H2); 
     252 
     253        TEST_ASSERT_WIN_WORLD_FOLDING(100, 250, 0,     H1+H2); 
     254        TEST_ASSERT_WIN_WORLD_FOLDING__BROKENIF(FACTOR >= 6, 400, 250, V1+V2, H1); 
     255 
     256        TEST_ASSERT_WIN_WORLD_FOLDING(100, 350, 0,  H1+H2); 
     257        TEST_ASSERT_WIN_WORLD_FOLDING__BROKENIF(FACTOR >= 3, 250, 350, V1, H1+H2); 
     258        TEST_ASSERT_WIN_WORLD_FOLDING(400, 350, V1, H1); 
     259    } 
     260} 
     261 
     262#endif // UNIT_TESTS 
     263 
     264// -------------------------------------------------------------------------------- 
    169265 
    170266short ED4_root::is_primary_selection(ED4_terminal *object) 
     
    680776ED4_returncode ED4_root::get_area_rectangle(AW_screen_area *rect, AW_pos x, AW_pos y) { 
    681777    // returns win-coordinates of area (defined by folding lines) which contains position x/y 
    682     ED4_folding_line      *flv, *flh; 
    683778    int                    x1, x2, y1, y2; 
    684779    const AW_screen_area&  area_rect = curr_device()->get_area_size(); 
    685780 
    686781    x1 = area_rect.l; 
    687     for (flv=curr_ed4w()->vertical_fl; ; flv = flv->next) { 
     782    for (const ED4_folding_line *flv=curr_ed4w()->get_vertical_folding(); ; flv = flv->next) { 
    688783        if (flv) { 
    689784            e4_assert(flv->length==INFINITE); 
     
    698793 
    699794        y1 = area_rect.t; 
    700         for (flh=curr_ed4w()->horizontal_fl; ; flh = flh->next) { 
     795        for (const ED4_folding_line *flh=curr_ed4w()->get_horizontal_folding(); ; flh = flh->next) { 
    701796            if (flh) { 
    702797                e4_assert(flh->length==INFINITE); 
  • branches/e4fix/EDIT4/ED4_window.cxx

    r8193 r8227  
    1717int ED4_window::no_of_windows = 0;                  // static variable has to be initialized only once 
    1818 
    19 void ED4_window::reset_all_for_new_config() 
    20 { 
    21     horizontal_fl = NULL; 
    22     vertical_fl   = NULL; 
     19void ED4_window::reset_all_for_new_config() { 
     20    ED4_foldable::reset(); 
    2321 
    2422    scrolled_rect.scroll_top    = NULL; 
     
    106104 
    107105 
    108 ED4_folding_line* ED4_window::insert_folding_line(AW_pos world_x, AW_pos world_y, AW_pos length, AW_pos dimension, ED4_base *link, ED4_properties prop) { 
     106ED4_folding_line* ED4_foldable::insert_folding_line(AW_pos world_x, AW_pos world_y, AW_pos length, AW_pos dimension, ED4_base *link, ED4_properties prop) { 
    109107    ED4_folding_line *fl = NULL; 
    110108 
     
    180178 
    181179 
    182 ED4_returncode ED4_window::delete_folding_line(ED4_folding_line */*fl*/, ED4_properties /*prop*/) { 
     180ED4_returncode ED4_foldable::delete_folding_line(ED4_folding_line */*fl*/, ED4_properties /*prop*/) { 
     181    e4_assert(0); // not implement - cause it's unused 
    183182    return ED4_R_OK; 
    184183} 
     
    576575    slider_pos_horizontal = 0; 
    577576    slider_pos_vertical   = 0; 
    578     horizontal_fl         = 0; 
    579     vertical_fl           = 0; 
    580577 
    581578    scrolled_rect.clear(); 
     
    601598 
    602599 
    603 ED4_window::~ED4_window() 
    604 { 
     600ED4_window::~ED4_window() { 
    605601    delete aww; 
    606     delete horizontal_fl;       // be careful, don't delete links to hierarchy  in folding lines!!! 
    607     delete vertical_fl; 
    608  
    609602    no_of_windows --; 
    610603} 
  • branches/e4fix/EDIT4/Makefile

    r8169 r8227  
    750750ED4_root.o: $(ARBHOME)/INCLUDE/svn_revision.h 
    751751ED4_root.o: $(ARBHOME)/INCLUDE/test_global.h 
     752ED4_root.o: $(ARBHOME)/INCLUDE/test_unit.h 
    752753 
    753754ED4_search.o: ed4_awars.hxx 
  • branches/e4fix/EDIT4/ed4_class.hxx

    r8222 r8227  
    467467}; 
    468468 
    469  
    470 class ED4_window : virtual Noncopyable { 
     469class ED4_foldable : virtual Noncopyable { 
     470    ED4_folding_line *horizontal_fl; 
     471    ED4_folding_line *vertical_fl; 
     472protected: 
     473    void reset() { 
     474        delete horizontal_fl; 
     475        delete vertical_fl; 
     476        horizontal_fl = NULL; 
     477        vertical_fl   = NULL; 
     478    } 
     479public: 
     480 
     481    ED4_foldable() : horizontal_fl(NULL), vertical_fl(NULL) {} 
     482    ~ED4_foldable() { reset(); } 
     483 
     484    const ED4_folding_line *get_horizontal_folding() { return horizontal_fl; } 
     485    const ED4_folding_line *get_vertical_folding() { return vertical_fl; } 
     486 
     487    void world_to_win_coords(AW_pos *x, AW_pos *y); 
     488    void win_to_world_coords(AW_pos *x, AW_pos *y); 
     489 
     490    ED4_folding_line *insert_folding_line(AW_pos world_x, AW_pos world_y, AW_pos length, AW_pos dimension, ED4_base *link, ED4_properties prop); 
     491    ED4_returncode  delete_folding_line(ED4_folding_line *fl, ED4_properties prop); 
     492}; 
     493 
     494class ED4_window : public ED4_foldable { // derived from Noncopyable 
    471495    ED4_window(const ED4_window&); // copy-constructor not allowed 
    472496public: 
     
    475499    int                     slider_pos_horizontal; 
    476500    int                     slider_pos_vertical; 
    477     ED4_folding_line       *horizontal_fl; 
    478     ED4_folding_line       *vertical_fl; 
    479501    ED4_scrolled_rectangle  scrolled_rect; 
    480502    int                     id; // unique id in window-list 
     
    507529    void update_window_coords(); 
    508530 
    509     // functions concerned with folding lines 
    510     ED4_folding_line    *insert_folding_line(AW_pos world_x, AW_pos world_y, AW_pos length, AW_pos dimension, ED4_base *link, ED4_properties prop); 
    511     ED4_returncode  delete_folding_line(ED4_folding_line *fl, ED4_properties prop); 
    512  
    513     // functions concerning coordinate transformation 
    514     void world_to_win_coords(AW_pos *x, AW_pos *y); 
    515     void win_to_world_coords(AW_pos *x, AW_pos *y); 
    516      
    517531    ED4_window(AW_window *window); 
    518532    ~ED4_window();