?login_element?

Subversion Repositories NedoOS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  1. /*
  2. Permission to use, copy, modify, and/or distribute this software for any purpose
  3. with or without fee is hereby granted.
  4.  
  5. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  6. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  7. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  8. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
  9. OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  10. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  11. OF THIS SOFTWARE.
  12. */
  13.  
  14. #ifdef ADD_UNIT_TESTS
  15.  
  16. #include "../sjasm/sjdefs.h"
  17. #include "UnitTest++/UnitTest++.h"
  18.  
  19. TEST(SjIo_FilenameExtPos_noInit) {
  20.         {
  21.                 char fname[LINEMAX] = { 0 };
  22.                 CHECK_EQUAL(fname, FilenameExtPos(fname));
  23.         }
  24.         {
  25.                 char fname[LINEMAX] = { "base" };
  26.                 CHECK_EQUAL(fname+4, FilenameExtPos(fname));
  27.         }
  28.         {
  29.                 char fname[LINEMAX] = { ".base" };
  30.                 CHECK_EQUAL(fname+5, FilenameExtPos(fname));
  31.         }
  32.         {
  33.                 char fname[LINEMAX] = { "base.ext" };
  34.                 CHECK_EQUAL(fname+4, FilenameExtPos(fname));
  35.         }
  36.         {
  37.                 char fname[LINEMAX] = { ".base.ext" };
  38.                 CHECK_EQUAL(fname+5, FilenameExtPos(fname));
  39.         }
  40.  
  41.         {
  42.                 char fname[LINEMAX] = { ".folder/" };
  43.                 CHECK_EQUAL(fname+8+0, FilenameExtPos(fname));
  44.         }
  45.         {
  46.                 char fname[LINEMAX] = { ".folder/base" };
  47.                 CHECK_EQUAL(fname+8+4, FilenameExtPos(fname));
  48.         }
  49.         {
  50.                 char fname[LINEMAX] = { ".folder/.base" };
  51.                 CHECK_EQUAL(fname+8+5, FilenameExtPos(fname));
  52.         }
  53.         {
  54.                 char fname[LINEMAX] = { ".folder/base.ext" };
  55.                 CHECK_EQUAL(fname+8+4, FilenameExtPos(fname));
  56.         }
  57.         {
  58.                 char fname[LINEMAX] = { ".folder/.base.ext" };
  59.                 CHECK_EQUAL(fname+8+5, FilenameExtPos(fname));
  60.         }
  61.  
  62.         {
  63.                 char fname[LINEMAX] = { ".folder\\" };
  64.                 CHECK_EQUAL(fname+8+0, FilenameExtPos(fname));
  65.         }
  66.         {
  67.                 char fname[LINEMAX] = { ".folder\\base" };
  68.                 CHECK_EQUAL(fname+8+4, FilenameExtPos(fname));
  69.         }
  70.         {
  71.                 char fname[LINEMAX] = { ".folder\\.base" };
  72.                 CHECK_EQUAL(fname+8+5, FilenameExtPos(fname));
  73.         }
  74.         {
  75.                 char fname[LINEMAX] = { ".folder\\base.ext" };
  76.                 CHECK_EQUAL(fname+8+4, FilenameExtPos(fname));
  77.         }
  78.         {
  79.                 char fname[LINEMAX] = { ".folder\\.base.ext" };
  80.                 CHECK_EQUAL(fname+8+5, FilenameExtPos(fname));
  81.         }
  82. }
  83.  
  84. TEST(SjIo_FilenameExtPos_WithInit) {
  85.         char fname[101];
  86.         fname[0] = 'x'; fname[1] = 0;
  87.         CHECK_EQUAL(fname, FilenameExtPos(fname, "", 100));             // init with empty string
  88.         fname[0] = 'x'; fname[1] = 0;
  89.         CHECK_EQUAL(fname+1, FilenameExtPos(fname, "bla.ext")); // no buffer size info => ignore init
  90.         fname[0] = 'x'; fname[1] = 0;
  91.         CHECK_EQUAL(fname+4, FilenameExtPos(fname, "base", 100));
  92.         fname[0] = 'x'; fname[1] = 0;
  93.         CHECK_EQUAL(fname+5, FilenameExtPos(fname, ".base", 100));
  94.         fname[0] = 'x'; fname[1] = 0;
  95.         CHECK_EQUAL(fname+4, FilenameExtPos(fname, "base.ext", 100));
  96.         fname[0] = 'x'; fname[1] = 0;
  97.         CHECK_EQUAL(fname+5, FilenameExtPos(fname, ".base.ext", 100));
  98.  
  99.         fname[0] = 'x'; fname[1] = 0;
  100.         CHECK_EQUAL(fname+8+0, FilenameExtPos(fname, ".folder/", 100));
  101.         fname[0] = 'x'; fname[1] = 0;
  102.         CHECK_EQUAL(fname+8+4, FilenameExtPos(fname, ".folder/base", 100));
  103.         fname[0] = 'x'; fname[1] = 0;
  104.         CHECK_EQUAL(fname+8+5, FilenameExtPos(fname, ".folder/.base", 100));
  105.         fname[0] = 'x'; fname[1] = 0;
  106.         CHECK_EQUAL(fname+8+4, FilenameExtPos(fname, ".folder/base.ext", 100));
  107.         fname[0] = 'x'; fname[1] = 0;
  108.         CHECK_EQUAL(fname+8+5, FilenameExtPos(fname, ".folder/.base.ext", 100));
  109.  
  110.         fname[0] = 'x'; fname[1] = 0;
  111.         CHECK_EQUAL(fname+8+0, FilenameExtPos(fname, ".folder\\", 100));
  112.         fname[0] = 'x'; fname[1] = 0;
  113.         CHECK_EQUAL(fname+8+4, FilenameExtPos(fname, ".folder\\base", 100));
  114.         fname[0] = 'x'; fname[1] = 0;
  115.         CHECK_EQUAL(fname+8+5, FilenameExtPos(fname, ".folder\\.base", 100));
  116.         fname[0] = 'x'; fname[1] = 0;
  117.         CHECK_EQUAL(fname+8+4, FilenameExtPos(fname, ".folder\\base.ext", 100));
  118.         fname[0] = 'x'; fname[1] = 0;
  119.         CHECK_EQUAL(fname+8+5, FilenameExtPos(fname, ".folder\\.base.ext", 100));
  120. }
  121.  
  122. TEST(SjIo_ConstructDefaultFilename) {
  123.         // verify the global sourceFiles variable is empty for this unit testing
  124.         CHECK_EQUAL(0, sourceFiles.size());
  125.         char fname[101];
  126.         // check the "checkIfDestIsEmpty" argument functionality, and default basename "asm"
  127.         fname[0] = 'x'; fname[1] = 0;
  128.         ConstructDefaultFilename(fname, 101, ".ext");
  129.         CHECK_EQUAL("x", fname);
  130.         ConstructDefaultFilename(fname, 101, ".ext", true);
  131.         CHECK_EQUAL("x", fname);
  132.         ConstructDefaultFilename(fname, 101, ".ext", false);
  133.         CHECK_EQUAL("asm.ext", fname);
  134.         fname[0] = 0;
  135.         ConstructDefaultFilename(fname, 101, ".ext");
  136.         CHECK_EQUAL("asm.ext", fname);
  137.         // check if first explicit filename is picked
  138.         sourceFiles.push_back(SSource(1));
  139.         ConstructDefaultFilename(fname, 101, ".ext", false);
  140.         CHECK_EQUAL("asm.ext", fname);
  141.         sourceFiles.push_back(SSource(".f1.asm"));
  142.         ConstructDefaultFilename(fname, 101, ".ext", false);
  143.         CHECK_EQUAL(".f1.ext", fname);
  144.         sourceFiles.push_back(SSource("f2.asm"));
  145.         ConstructDefaultFilename(fname, 101, ".ext", false);
  146.         CHECK_EQUAL(".f1.ext", fname);
  147.         // empty the global sourceFiles again
  148.         sourceFiles.clear();
  149. }
  150.  
  151. #endif
  152.