/usr.bin/cpio/test/test_option_t.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 95 lines · 46 code · 9 blank · 40 comment · 8 complexity · ce423ff0ac41eb958fb580389cd4ac78 MD5 · raw file

  1. /*-
  2. * Copyright (c) 2003-2007 Tim Kientzle
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "test.h"
  26. __FBSDID("$FreeBSD$");
  27. DEFINE_TEST(test_option_t)
  28. {
  29. char *p;
  30. int r;
  31. /* List reference archive, make sure the TOC is correct. */
  32. extract_reference_file("test_option_t.cpio");
  33. r = systemf("%s -it < test_option_t.cpio >it.out 2>it.err", testprog);
  34. assertEqualInt(r, 0);
  35. assertTextFileContents("1 block\n", "it.err");
  36. extract_reference_file("test_option_t.stdout");
  37. p = slurpfile(NULL, "test_option_t.stdout");
  38. assertTextFileContents(p, "it.out");
  39. free(p);
  40. /* We accept plain "-t" as a synonym for "-it" */
  41. r = systemf("%s -t < test_option_t.cpio >t.out 2>t.err", testprog);
  42. assertEqualInt(r, 0);
  43. assertTextFileContents("1 block\n", "t.err");
  44. extract_reference_file("test_option_t.stdout");
  45. p = slurpfile(NULL, "test_option_t.stdout");
  46. assertTextFileContents(p, "t.out");
  47. free(p);
  48. /* But "-ot" is an error. */
  49. assert(0 != systemf("%s -ot < test_option_t.cpio >ot.out 2>ot.err",
  50. testprog));
  51. assertEmptyFile("ot.out");
  52. /* List reference archive verbosely, make sure the TOC is correct. */
  53. r = systemf("%s -itv < test_option_t.cpio >tv.out 2>tv.err", testprog);
  54. assertEqualInt(r, 0);
  55. assertTextFileContents("1 block\n", "tv.err");
  56. extract_reference_file("test_option_tv.stdout");
  57. /* This doesn't work because the usernames on different systems
  58. * are different and cpio now looks up numeric UIDs on
  59. * the local system. */
  60. /* assertEqualFile("tv.out", "test_option_tv.stdout"); */
  61. /* List reference archive with numeric IDs, verify TOC is correct. */
  62. r = systemf("%s -itnv < test_option_t.cpio >itnv.out 2>itnv.err",
  63. testprog);
  64. assertEqualInt(r, 0);
  65. assertTextFileContents("1 block\n", "itnv.err");
  66. p = slurpfile(NULL, "itnv.out");
  67. /* Since -n uses numeric UID/GID, this part should be the
  68. * same on every system. */
  69. assertEqualMem(p, "-rw-r--r-- 1 1000 1000 0 ",42);
  70. /* Date varies depending on local timezone. */
  71. if (memcmp(p + 42, "Dec 31 1969", 12) == 0) {
  72. /* East of Greenwich we get Dec 31, 1969. */
  73. } else {
  74. /* West of Greenwich get Jan 1, 1970 */
  75. assertEqualMem(p + 42, "Jan ", 4);
  76. /* Some systems format "Jan 01", some "Jan 1" */
  77. assert(p[46] == ' ' || p[46] == '0');
  78. assertEqualMem(p + 47, "1 1970 ", 8);
  79. }
  80. assertEqualMem(p + 54, " file", 5);
  81. free(p);
  82. /* But "-n" without "-t" is an error. */
  83. assert(0 != systemf("%s -in < test_option_t.cpio >in.out 2>in.err",
  84. testprog));
  85. assertEmptyFile("in.out");
  86. }