1 /******************************************************************************* 2 3 Integration tests for `ocean.util.container.queue.FlexibleFileQueue` 4 5 Those tests perform I/O operations. 6 7 Copyright: 8 Copyright (c) 2009-2016 dunnhumby Germany GmbH. 9 All rights reserved. 10 11 *******************************************************************************/ 12 13 module integrationtest.flexiblefilequeue.main; 14 15 import ocean.meta.types.Qualifiers; 16 import ocean.io.Stdout; 17 import ocean.text.util.StringC; 18 import ocean.util.container.queue.FlexibleFileQueue; 19 import ocean.util.test.DirectorySandbox; 20 21 version (unittest) {} else 22 public void main () 23 { 24 // Create will cd us into the sandbox 25 auto test_dir = DirectorySandbox.create(["flexiblefilequeue"]); 26 scope (exit) test_dir.remove(); 27 28 static immutable istring test_file = "testfile"; 29 30 31 static void pushItems (FlexibleFileQueue queue, size_t size) 32 { 33 for (ubyte i = 0; i < size; i++) 34 { 35 auto item = [i, cast(ubyte) (ubyte.max-i), i, cast(ubyte) (i * i)]; 36 assert(queue.push(item), "push failed"); 37 } 38 } 39 40 static void popItems (FlexibleFileQueue queue, size_t size) 41 { 42 for (ubyte i = 0; i < size; i++) 43 { 44 auto pop = queue.pop; 45 auto item = [i, cast(ubyte)(ubyte.max - i), i, cast(ubyte) (i * i)]; 46 assert(pop == item, "pop failed " ~ pop.stringof); 47 } 48 } 49 50 void doTest (bool open_existing) 51 { 52 for (ubyte size; size < ubyte.max; size++) 53 { 54 auto queue = new FlexibleFileQueue(test_file, 4, open_existing); 55 pushItems(queue, size); 56 popItems(queue, size); 57 queue.clear(); 58 } 59 } 60 61 doTest(false); 62 doTest(true); 63 64 void reopenTestWrite () 65 { 66 scope queue = new FlexibleFileQueue(test_file, 4, true); 67 assert(queue.is_empty()); 68 assert(queue.length() == 0); 69 pushItems(queue, 100); 70 assert(!queue.is_empty()); 71 assert(queue.length() == 100); 72 } 73 74 void reopenTestRead () 75 { 76 scope queue = new FlexibleFileQueue(test_file, 4, true); 77 assert(!queue.is_empty()); 78 assert(queue.length() == 100); 79 popItems(queue, 100); 80 assert(queue.is_empty()); 81 assert(queue.length() == 0); 82 } 83 84 reopenTestWrite(); 85 reopenTestRead(); 86 }