~s-cecilio/lomse/master

« back to all changes in this revision

Viewing changes to src/tests/lomse_test_internal_model.cpp

  • Committer: cecilios
  • Date: 2010-10-10 13:35:19 UTC
  • Revision ID: git-v1:2b333198c3033525d15763b84eaf79dac9fdab80
Preparing to use CMake. Updating with new code and missing files. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
//  You should have received a copy of the GNU General Public License along
14
14
//  with Lomse; if not, see <http://www.gnu.org/licenses/>.
15
15
//  
16
 
//  
17
 
//
18
16
//  For any comment, suggestion or feature request, please contact the manager of
19
17
//  the project at cecilios@users.sourceforge.net
20
18
//
21
19
//-------------------------------------------------------------------------------------
22
20
 
23
 
#ifdef _LM_DEBUG_
 
21
#ifdef _LOMSE_DEBUG
24
22
 
25
23
#include <UnitTest++.h>
26
24
#include <sstream>
29
27
//classes related to these tests
30
28
#include "lomse_injectors.h"
31
29
#include "lomse_internal_model.h"
 
30
#include "lomse_im_figured_bass.h"
32
31
#include "lomse_basic_model.h"
33
32
 
34
33
using namespace UnitTest;
43
42
    InternalModelTestFixture()     //SetUp fixture
44
43
    {
45
44
        m_pLibraryScope = new LibraryScope(cout);
46
 
        m_scores_path = LML_TEST_SCORES_PATH;
 
45
        m_scores_path = LOMSE_TEST_SCORES_PATH;
47
46
    }
48
47
 
49
48
    ~InternalModelTestFixture()    //TearDown fixture
69
68
    {
70
69
        ImoClef* pClef = new ImoClef(ImoClef::k_G3);
71
70
        CHECK( pClef->has_attachments() == false );
72
 
        ImoTextString* pText = new ImoTextString("Hello world");
 
71
        ImoScoreText* pText = new ImoScoreText("Hello world");
73
72
        pClef->attach(pText);
74
73
        CHECK( pClef->has_attachments() == true );
75
74
        ImoObj* pImo = pClef->get_attachment(0);
76
 
        CHECK( pImo->is_text_string() );
77
 
        ImoTextString* pTS = dynamic_cast<ImoTextString*>( pImo );
 
75
        CHECK( pImo->is_score_text() );
 
76
        ImoScoreText* pTS = dynamic_cast<ImoScoreText*>( pImo );
78
77
        CHECK( pTS->get_text() == "Hello world" );
79
78
        delete pClef;
80
79
    }
94
93
        ImoDocument* pDoc = new ImoDocument();
95
94
        ImoContent* pContent = new ImoContent();
96
95
        pDoc->append_child(pContent);
97
 
        ImoTextString* pText = new ImoTextString("Hello world");
 
96
        ImoScoreText* pText = new ImoScoreText("Hello world");
98
97
        pContent->append_child(pText);
99
98
        CHECK( pDoc->get_num_content_items() == 1 );
100
99
        CHECK( pDoc->get_content_item(0) == pText );
157
156
        ImoMusicData* pMD = new ImoMusicData();
158
157
        pInstr->append_child(pMD);
159
158
        ImoClef* pClef = new ImoClef(ImoClef::k_G3);
160
 
        ImoTextString* pText = new ImoTextString("Hello world");
 
159
        ImoScoreText* pText = new ImoScoreText("Hello world");
161
160
        pClef->attach(pText);
162
161
        pMD->append_child(pClef);
163
162
        pScore->add_instrument(pInstr);
235
234
        ImoMusicData* pMD = new ImoMusicData();
236
235
        pInstr->append_child(pMD);
237
236
        ImoClef* pClef = new ImoClef(ImoClef::k_G3);
238
 
        ImoTextString* pText = new ImoTextString("Hello world");
 
237
        ImoScoreText* pText = new ImoScoreText("Hello world");
239
238
        pClef->attach(pText);
240
239
        pMD->append_child(pClef);
241
240
        pScore->add_instrument(pInstr);
249
248
        delete pDoc;
250
249
    }
251
250
 
 
251
    // ImoPageInfo ---------------------------------------------------------------
 
252
 
 
253
    TEST_FIXTURE(InternalModelTestFixture, InternalModel_PageInfoDefaults)
 
254
    {
 
255
        ImoPageInfo info;
 
256
        CHECK( info.is_page_info() == true );
 
257
        CHECK( info.get_top_margin() == 2000.0f );
 
258
        CHECK( info.get_bottom_margin() == 2000.0f );
 
259
        CHECK( info.get_left_margin() == 2000.0f );
 
260
        CHECK( info.get_right_margin() == 1500.0f );
 
261
        CHECK( info.get_binding_margin() == 0.0f );
 
262
        CHECK( info.is_portrait() == true );
 
263
    }
 
264
 
 
265
    // ImoTextStyleInfo ---------------------------------------------------------
 
266
 
 
267
    TEST_FIXTURE(InternalModelTestFixture, InternalModel_Score_GetDefaultStyle)
 
268
    {
 
269
        ImoScore score;
 
270
        ImoTextStyleInfo* pStyle = score.get_default_style_info();
 
271
        CHECK( pStyle != NULL );
 
272
        CHECK( pStyle->get_name() == "Default style" );
 
273
        CHECK( pStyle->get_color() == rgba16(0,0,0,255) );
 
274
        CHECK( pStyle->get_font_name() == "Times New Roman" );
 
275
        CHECK( pStyle->get_font_style() == ImoFontInfo::k_normal );
 
276
        CHECK( pStyle->get_font_weight() == ImoFontInfo::k_normal );
 
277
        CHECK( pStyle->get_font_size() == 10 );
 
278
    }
 
279
 
 
280
    TEST_FIXTURE(InternalModelTestFixture, InternalModel_Score_GetStyle)
 
281
    {
 
282
        ImoScore score;
 
283
            ImoTextStyleInfo* pStyle = new ImoTextStyleInfo();
 
284
            pStyle->set_name("Test style");
 
285
        pStyle->set_color( rgba16(15,16,27,132) );
 
286
        pStyle->set_font_name("Callamet");
 
287
        pStyle->set_font_size(12);
 
288
        pStyle->set_font_style(ImoFontInfo::k_normal);
 
289
        pStyle->set_font_weight(ImoFontInfo::k_bold);
 
290
        score.add_style_info(pStyle);
 
291
 
 
292
        ImoTextStyleInfo* pStyle2 = score.get_style_info("Test style");
 
293
        CHECK( pStyle == pStyle2 );
 
294
    }
 
295
 
 
296
    // ImoBoxInfo -------------------------------------------------------------
 
297
 
 
298
    TEST_FIXTURE(InternalModelTestFixture, InternalModel_BoxInfoDefaults)
 
299
    {
 
300
        ImoBoxInfo info;
 
301
        CHECK( info.is_box_info() == true );
 
302
        CHECK( info.get_height() == 100.0f );
 
303
        CHECK( info.get_width() == 160.0f );
 
304
        CHECK( info.get_position() == TPoint(0.0f, 0.0f) );
 
305
        CHECK( info.get_bg_color() == rgba16(255,255,255,255) );
 
306
        CHECK( info.get_border_color() == rgba16(0,0,0,255) );
 
307
        CHECK( info.get_border_width() == 1.0f );
 
308
        CHECK( info.get_border_style() == k_line_solid );
 
309
    }
 
310
 
 
311
    // ImoCursorInfo -------------------------------------------------------------
 
312
 
 
313
    TEST_FIXTURE(InternalModelTestFixture, InternalModel_CursorInfoDefaults)
 
314
    {
 
315
        ImoCursorInfo info;
 
316
        CHECK( info.is_cursor_info() == true );
 
317
        CHECK( info.get_instrument() == 0 );
 
318
        CHECK( info.get_staff() == 0 );
 
319
        CHECK( info.get_time() == 0.0f );
 
320
        CHECK( info.get_id() == -1L );
 
321
    }
 
322
 
 
323
    // ImoFiguredBassInfo ---------------------------------------------------------
 
324
 
 
325
    TEST_FIXTURE(InternalModelTestFixture, InternalModel_FigBasInfoFromString_63)
 
326
    {
 
327
        ImoFiguredBassInfo info("6 3");
 
328
        CHECK( info.get_quality(3) == k_interval_as_implied );
 
329
        CHECK( info.get_source(3) == "3" );
 
330
        CHECK( info.get_prefix(3) == "" );
 
331
        CHECK( info.get_suffix(3) == "" );
 
332
        CHECK( info.get_over(3) == "" );
 
333
        CHECK( info.get_figured_bass_string() == "6 3" );
 
334
    }
 
335
 
 
336
    TEST_FIXTURE(InternalModelTestFixture, InternalModel_FigBasInfoFromString_5)
 
337
    {
 
338
        ImoFiguredBassInfo info("5");
 
339
        //CHECK( info.get_quality(3) == k_interval_as_implied );
 
340
        //CHECK( info.get_source(3) == "3" );
 
341
        //CHECK( info.get_prefix(3) == "" );
 
342
        //CHECK( info.get_suffix(3) == "" );
 
343
        //CHECK( info.get_over(3) == "" );
 
344
        CHECK( info.get_figured_bass_string() == "5" );
 
345
    }
 
346
 
 
347
    TEST_FIXTURE(InternalModelTestFixture, InternalModel_FigBasInfoFromString_6)
 
348
    {
 
349
        ImoFiguredBassInfo info("6");
 
350
        //CHECK( info.get_quality(3) == k_interval_as_implied );
 
351
        //CHECK( info.get_source(3) == "3" );
 
352
        //CHECK( info.get_prefix(3) == "" );
 
353
        //CHECK( info.get_suffix(3) == "" );
 
354
        //CHECK( info.get_over(3) == "" );
 
355
        CHECK( info.get_figured_bass_string() == "6" );
 
356
    }
 
357
 
 
358
    TEST_FIXTURE(InternalModelTestFixture, InternalModel_FigBasInfoFromString_64)
 
359
    {
 
360
        ImoFiguredBassInfo info("6 4");
 
361
        //CHECK( info.get_quality(3) == k_interval_as_implied );
 
362
        //CHECK( info.get_source(3) == "3" );
 
363
        //CHECK( info.get_prefix(3) == "" );
 
364
        //CHECK( info.get_suffix(3) == "" );
 
365
        //CHECK( info.get_over(3) == "" );
 
366
        CHECK( info.get_figured_bass_string() == "6 4" );
 
367
    }
 
368
 
 
369
    TEST_FIXTURE(InternalModelTestFixture, InternalModel_FigBasInfoFromString_7)
 
370
    {
 
371
        ImoFiguredBassInfo info("7");
 
372
        //CHECK( info.get_quality(3) == k_interval_as_implied );
 
373
        //CHECK( info.get_source(3) == "3" );
 
374
        //CHECK( info.get_prefix(3) == "" );
 
375
        //CHECK( info.get_suffix(3) == "" );
 
376
        //CHECK( info.get_over(3) == "" );
 
377
        CHECK( info.get_figured_bass_string() == "7" );
 
378
    }
 
379
 
 
380
    TEST_FIXTURE(InternalModelTestFixture, InternalModel_FigBasInfoFromString_7m)
 
381
    {
 
382
        ImoFiguredBassInfo info("7/");
 
383
        //CHECK( info.get_quality(3) == k_interval_as_implied );
 
384
        //CHECK( info.get_source(3) == "3" );
 
385
        //CHECK( info.get_prefix(3) == "" );
 
386
        //CHECK( info.get_suffix(3) == "" );
 
387
        //CHECK( info.get_over(3) == "" );
 
388
        CHECK( info.get_figured_bass_string() == "7/" );
 
389
    }
 
390
 
 
391
    TEST_FIXTURE(InternalModelTestFixture, InternalModel_FigBasInfoFromString_4)
 
392
    {
 
393
        ImoFiguredBassInfo info("4");   //5 4
 
394
        CHECK( info.is_sounding(3) == false );
 
395
        CHECK( info.is_sounding(5) == true );
 
396
        CHECK( info.get_figured_bass_string() == "4" );
 
397
    }
 
398
 
 
399
    TEST_FIXTURE(InternalModelTestFixture, InternalModel_FigBasInfoFromString_9)
 
400
    {
 
401
        ImoFiguredBassInfo info("9");
 
402
        //CHECK( info.get_quality(3) == k_interval_as_implied );
 
403
        //CHECK( info.get_source(3) == "3" );
 
404
        //CHECK( info.get_prefix(3) == "" );
 
405
        //CHECK( info.get_suffix(3) == "" );
 
406
        //CHECK( info.get_over(3) == "" );
 
407
        CHECK( info.get_figured_bass_string() == "9" );
 
408
    }
 
409
 
252
410
}
253
411
 
254
412
 
255
 
#endif  // _LM_DEBUG_
 
413
#endif  // _LOMSE_DEBUG
256
414