~mbranton/libopenshot/alpha-channel-fix

« back to all changes in this revision

Viewing changes to tests/Cache_Tests.cpp

  • Committer: Jonathan Thomas
  • Date: 2016-09-07 05:40:01 UTC
  • Revision ID: jonathan@openshot.org-20160907054001-v2tbe8uy8a7lk4qw
Added new CacheDisk class, which caches frames to the hard drive, dramatically speeding up preview speeds, at the expense of IO operations. New unittests for caching framework. Fixed a few bugs with Frame constructor, which was causing invalid # width & height. Integrated JSON into the cache framework, to quickly share the state of the cache (including ranges of cached frame numbers). Fixed a bug where some Timeline frames could have no audio samples.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
#include "UnitTest++.h"
29
29
#include "../include/OpenShot.h"
 
30
#include "../include/Json.h"
30
31
 
31
32
using namespace std;
32
33
using namespace openshot;
270
271
        c.SetMaxBytes(4 * 1024);
271
272
        CHECK_EQUAL(4 * 1024, c.GetMaxBytes());
272
273
}
 
274
 
 
275
TEST(CacheDisk_Set_Max_Bytes)
 
276
{
 
277
        // Create cache object (using platform /temp/ directory)
 
278
        CacheDisk c("", "PPM", 1.0, 0.25);
 
279
 
 
280
        // Add frames to disk cache
 
281
        for (int i = 0; i < 20; i++)
 
282
        {
 
283
                // Add blank frame to the cache
 
284
                tr1::shared_ptr<Frame> f(new Frame());
 
285
                f->number = i;
 
286
                // Add some picture data
 
287
                f->AddColor(1280, 720, "Blue");
 
288
                f->ResizeAudio(2, 500, 44100, LAYOUT_STEREO);
 
289
                f->AddAudioSilence(500);
 
290
                c.Add(f);
 
291
        }
 
292
 
 
293
        CHECK_EQUAL(0, c.GetMaxBytes()); // Cache defaults max frames to -1, unlimited frames
 
294
 
 
295
        // Set max frames
 
296
        c.SetMaxBytes(8 * 1024);
 
297
        CHECK_EQUAL(8 * 1024, c.GetMaxBytes());
 
298
 
 
299
        // Set max frames
 
300
        c.SetMaxBytes(4 * 1024);
 
301
        CHECK_EQUAL(4 * 1024, c.GetMaxBytes());
 
302
 
 
303
        // Read frames from disk cache
 
304
        tr1::shared_ptr<Frame> f = c.GetFrame(5);
 
305
        CHECK_EQUAL(320, f->GetWidth());
 
306
        CHECK_EQUAL(180, f->GetHeight());
 
307
        CHECK_EQUAL(2, f->GetAudioChannelsCount());
 
308
        CHECK_EQUAL(500, f->GetAudioSamplesCount());
 
309
        CHECK_EQUAL(LAYOUT_STEREO, f->ChannelsLayout());
 
310
        CHECK_EQUAL(44100, f->SampleRate());
 
311
 
 
312
}
 
313
 
 
314
TEST(CacheDisk_JSON)
 
315
{
 
316
        // Create cache object (using platform /temp/ directory)
 
317
        CacheDisk c("", "PPM", 1.0, 0.25);
 
318
 
 
319
        // Add some frames (out of order)
 
320
        tr1::shared_ptr<Frame> f3(new Frame(3, 1280, 720, "Blue", 500, 2));
 
321
        c.Add(f3);
 
322
        CHECK_EQUAL(1, c.JsonValue()["ranges"].size());
 
323
        CHECK_EQUAL("1", c.JsonValue()["version"].asString());
 
324
 
 
325
        // Add some frames (out of order)
 
326
        tr1::shared_ptr<Frame> f1(new Frame(1, 1280, 720, "Blue", 500, 2));
 
327
        c.Add(f1);
 
328
        CHECK_EQUAL(2, c.JsonValue()["ranges"].size());
 
329
        CHECK_EQUAL("2", c.JsonValue()["version"].asString());
 
330
 
 
331
        // Add some frames (out of order)
 
332
        tr1::shared_ptr<Frame> f2(new Frame(2, 1280, 720, "Blue", 500, 2));
 
333
        c.Add(f2);
 
334
        CHECK_EQUAL(1, c.JsonValue()["ranges"].size());
 
335
        CHECK_EQUAL("3", c.JsonValue()["version"].asString());
 
336
 
 
337
        // Add some frames (out of order)
 
338
        tr1::shared_ptr<Frame> f5(new Frame(5, 1280, 720, "Blue", 500, 2));
 
339
        c.Add(f5);
 
340
        CHECK_EQUAL(2, c.JsonValue()["ranges"].size());
 
341
        CHECK_EQUAL("4", c.JsonValue()["version"].asString());
 
342
 
 
343
        // Add some frames (out of order)
 
344
        tr1::shared_ptr<Frame> f4(new Frame(4, 1280, 720, "Blue", 500, 2));
 
345
        c.Add(f4);
 
346
        CHECK_EQUAL(1, c.JsonValue()["ranges"].size());
 
347
        CHECK_EQUAL("5", c.JsonValue()["version"].asString());
 
348
 
 
349
}
 
350
 
 
351
TEST(CacheMemory_JSON)
 
352
{
 
353
        // Create memory cache object
 
354
        CacheMemory c;
 
355
 
 
356
        // Add some frames (out of order)
 
357
        tr1::shared_ptr<Frame> f3(new Frame(3, 1280, 720, "Blue", 500, 2));
 
358
        c.Add(f3);
 
359
        CHECK_EQUAL(1, c.JsonValue()["ranges"].size());
 
360
        CHECK_EQUAL("1", c.JsonValue()["version"].asString());
 
361
 
 
362
        // Add some frames (out of order)
 
363
        tr1::shared_ptr<Frame> f1(new Frame(1, 1280, 720, "Blue", 500, 2));
 
364
        c.Add(f1);
 
365
        CHECK_EQUAL(2, c.JsonValue()["ranges"].size());
 
366
        CHECK_EQUAL("2", c.JsonValue()["version"].asString());
 
367
 
 
368
        // Add some frames (out of order)
 
369
        tr1::shared_ptr<Frame> f2(new Frame(2, 1280, 720, "Blue", 500, 2));
 
370
        c.Add(f2);
 
371
        CHECK_EQUAL(1, c.JsonValue()["ranges"].size());
 
372
        CHECK_EQUAL("3", c.JsonValue()["version"].asString());
 
373
 
 
374
        // Add some frames (out of order)
 
375
        tr1::shared_ptr<Frame> f5(new Frame(5, 1280, 720, "Blue", 500, 2));
 
376
        c.Add(f5);
 
377
        CHECK_EQUAL(2, c.JsonValue()["ranges"].size());
 
378
        CHECK_EQUAL("4", c.JsonValue()["version"].asString());
 
379
 
 
380
        // Add some frames (out of order)
 
381
        tr1::shared_ptr<Frame> f4(new Frame(4, 1280, 720, "Blue", 500, 2));
 
382
        c.Add(f4);
 
383
        CHECK_EQUAL(1, c.JsonValue()["ranges"].size());
 
384
        CHECK_EQUAL("5", c.JsonValue()["version"].asString());
 
385
 
 
386
}
 
 
b'\\ No newline at end of file'