?login_element?

Subversion Repositories NedoOS

Rev

Rev 539 | 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(SjIoTrd_FilenameToBytes) {
  20.         // the ones with (?) are ad-hoc and maybe not the best possible choice
  21.         {       //(?) empty input string -> all spaces name
  22.                 const char fname[LINEMAX] = { 0 };
  23.                 const byte expected[12] = { "         " };
  24.                 byte binName[12] = { 0 };
  25.                 int length = 1234;
  26.                 CHECK_EQUAL(INVALID_EXTENSION, TRD_FileNameToBytes(fname, binName, length));
  27.                 CHECK_EQUAL(9, length);
  28.                 CHECK_ARRAY_EQUAL(expected, binName, 12);
  29.         }
  30.  
  31.         {       // short name without extension
  32.                 const char fname[LINEMAX] = { "a" };
  33.                 const byte expected[12] = { "a        " };
  34.                 byte binName[12] = { 0 };
  35.                 int length = 1234;
  36.                 CHECK_EQUAL(INVALID_EXTENSION, TRD_FileNameToBytes(fname, binName, length));
  37.                 CHECK_EQUAL(9, length);
  38.                 CHECK_ARRAY_EQUAL(expected, binName, 12);
  39.         }
  40.  
  41.         {       // short name with extension
  42.                 const char fname[LINEMAX] = { "a.a" };
  43.                 const byte expected[12] = { "a       a" };
  44.                 byte binName[12] = { 0 };
  45.                 int length = 1234;
  46.                 CHECK_EQUAL(INVALID_EXTENSION, TRD_FileNameToBytes(fname, binName, length));
  47.                 CHECK_EQUAL(9, length);
  48.                 CHECK_ARRAY_EQUAL(expected, binName, 12);
  49.         }
  50.  
  51.         {       // short name with valid extension "B"
  52.                 const char fname[LINEMAX] = { "a.B" };
  53.                 const byte expected[12] = { "a       B" };
  54.                 byte binName[12] = { 0 };
  55.                 int length = 1234;
  56.                 CHECK_EQUAL(OK, TRD_FileNameToBytes(fname, binName, length));
  57.                 CHECK_EQUAL(9, length);
  58.                 CHECK_ARRAY_EQUAL(expected, binName, 12);
  59.         }
  60.  
  61.         {       // short name with long extension (but only two letters)
  62.                 const char fname[LINEMAX] = { "a.CI" };
  63.                 const byte expected[12] = { "a       CI " };
  64.                 byte binName[12] = { 0 };
  65.                 int length = 1234;
  66.                 CHECK_EQUAL(THREE_LETTER_EXTENSION, TRD_FileNameToBytes(fname, binName, length));
  67.                 CHECK_EQUAL(11, length);
  68.                 CHECK_ARRAY_EQUAL(expected, binName, 12);
  69.         }
  70.  
  71.         {       // short name with long extension
  72.                 const char fname[LINEMAX] = { "a.mp3" };
  73.                 const byte expected[12] = { "a       mp3" };
  74.                 byte binName[12] = { 0 };
  75.                 int length = 1234;
  76.                 CHECK_EQUAL(THREE_LETTER_EXTENSION, TRD_FileNameToBytes(fname, binName, length));
  77.                 CHECK_EQUAL(11, length);
  78.                 CHECK_ARRAY_EQUAL(expected, binName, 12);
  79.         }
  80.  
  81.         {       // short name with too long extension
  82.                 const char fname[LINEMAX] = { "img.jpeg" };
  83.                 const byte expected[12] = { "img     jpe" };
  84.                 byte binName[12] = { 0 };
  85.                 int length = 1234;
  86.                 CHECK_EQUAL(THREE_LETTER_EXTENSION, TRD_FileNameToBytes(fname, binName, length));
  87.                 CHECK_EQUAL(11, length);
  88.                 CHECK_ARRAY_EQUAL(expected, binName, 12);
  89.         }
  90.  
  91.         {       // too long name with valid extension "C"
  92.                 const char fname[LINEMAX] = { "longername.C" };
  93.                 const byte expected[12] = { "longernaC" };
  94.                 byte binName[12] = { 0 };
  95.                 int length = 1234;
  96.                 CHECK_EQUAL(OK, TRD_FileNameToBytes(fname, binName, length));
  97.                 CHECK_EQUAL(9, length);
  98.                 CHECK_ARRAY_EQUAL(expected, binName, 12);
  99.         }
  100.  
  101.         {       // 8 letters name with valid ext. "D"
  102.                 const char fname[LINEMAX] = { "12345678.D" };
  103.                 const byte expected[12] = { "12345678D" };
  104.                 byte binName[12] = { 0 };
  105.                 int length = 1234;
  106.                 CHECK_EQUAL(OK, TRD_FileNameToBytes(fname, binName, length));
  107.                 CHECK_EQUAL(9, length);
  108.                 CHECK_ARRAY_EQUAL(expected, binName, 12);
  109.         }
  110.  
  111.         {       // 8 letters name with valid ext. "#"
  112.                 const char fname[LINEMAX] = { "_!@#$%^&.#" };
  113.                 const byte expected[12] = { "_!@#$%^&#" };
  114.                 byte binName[12] = { 0 };
  115.                 int length = 1234;
  116.                 CHECK_EQUAL(OK, TRD_FileNameToBytes(fname, binName, length));
  117.                 CHECK_EQUAL(9, length);
  118.                 CHECK_ARRAY_EQUAL(expected, binName, 12);
  119.         }
  120.  
  121.         {       // name with dots inside is valid name and does use last dot as extension separator
  122.                 // (behaviour requested by Dart_Alver from zx-pk.ru forums)
  123.                 const char fname[LINEMAX] = { "a.b.c.C" };
  124.                 const byte expected[12] = { "a.b.c   C" };
  125.                 byte binName[12] = { 0 };
  126.                 int length = 1234;
  127.                 CHECK_EQUAL(OK, TRD_FileNameToBytes(fname, binName, length));
  128.                 CHECK_EQUAL(9, length);
  129.                 CHECK_ARRAY_EQUAL(expected, binName, 12);
  130.         }
  131.  
  132.         {       // same as previous, but too long name should be trimmed
  133.                 const char fname[LINEMAX] = { "a.b.c.d.e.C" };
  134.                 const byte expected[12] = { "a.b.c.d.C" };
  135.                 byte binName[12] = { 0 };
  136.                 int length = 1234;
  137.                 CHECK_EQUAL(OK, TRD_FileNameToBytes(fname, binName, length));
  138.                 CHECK_EQUAL(9, length);
  139.                 CHECK_ARRAY_EQUAL(expected, binName, 12);
  140.         }
  141. }
  142.  
  143. #endif
  144.