Skip to content
This repository
Browse code

Add test case for uncompressed RAR archive with directories and symli…

…nks.
  • Loading branch information...
commit 7efb0d735808431c3a3f1aae8dce56ece07c1eca 1 parent fde9c92
Andres Mejia authored January 19, 2013
227  xbmc/filesystem/test/TestRarFile.cpp
@@ -26,6 +26,7 @@
26 26
 #include "utils/URIUtils.h"
27 27
 #include "FileItem.h"
28 28
 #include "test/TestUtils.h"
  29
+#include "utils/StringUtils.h"
29 30
 
30 31
 #include <errno.h>
31 32
 
@@ -188,4 +189,230 @@ TEST(TestRarFile, CorruptedFile)
188 189
   file->Close();
189 190
   XBMC_DELETETEMPFILE(file);
190 191
 }
  192
+
  193
+TEST(TestRarFile, StoredRAR)
  194
+{
  195
+  XFILE::CFile file;
  196
+  char buf[20];
  197
+  memset(&buf, 0, sizeof(buf));
  198
+  CStdString reffile, strrarpath, strpathinrar;
  199
+  CFileItemList itemlist, itemlistemptydir;
  200
+  struct __stat64 stat_buffer;
  201
+
  202
+  reffile = XBMC_REF_FILE_PATH("xbmc/filesystem/test/refRARstored.rar");
  203
+  URIUtils::CreateArchivePath(strrarpath, "rar", reffile, "");
  204
+  ASSERT_TRUE(XFILE::CDirectory::GetDirectory(strrarpath, itemlist));
  205
+  itemlist.Sort(SORT_METHOD_FULLPATH, SortOrderAscending);
  206
+
  207
+  /* /reffile.txt */
  208
+  /*
  209
+   * NOTE: Use of Seek gives inconsistent behavior from when seeking through
  210
+   * an uncompressed RAR archive. See TestRarFile.Read test case.
  211
+   */
  212
+  strpathinrar = itemlist[1]->GetPath();
  213
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/reffile.txt", true));
  214
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  215
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFREG);
  216
+
  217
+  ASSERT_TRUE(file.Open(strpathinrar));
  218
+  EXPECT_EQ(0, file.GetPosition());
  219
+  EXPECT_EQ(1616, file.GetLength());
  220
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  221
+  file.Flush();
  222
+  EXPECT_EQ(20, file.GetPosition());
  223
+  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  224
+  EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
  225
+  EXPECT_EQ(39, file.GetPosition());
  226
+  EXPECT_STREQ("an award-winning fr", buf);
  227
+  EXPECT_EQ(100, file.Seek(100));
  228
+  EXPECT_EQ(100, file.GetPosition());
  229
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  230
+  file.Flush();
  231
+  EXPECT_EQ(120, file.GetPosition());
  232
+  EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
  233
+  EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
  234
+  EXPECT_EQ(220, file.GetPosition());
  235
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  236
+  file.Flush();
  237
+  EXPECT_EQ(240, file.GetPosition());
  238
+  EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
  239
+  EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
  240
+  EXPECT_EQ(1596, file.GetPosition());
  241
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  242
+  file.Flush();
  243
+  EXPECT_EQ(1616, file.GetPosition());
  244
+  EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
  245
+  EXPECT_EQ(-1, file.Seek(100, SEEK_CUR));
  246
+  EXPECT_EQ(1616, file.GetPosition());
  247
+  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  248
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  249
+  file.Flush();
  250
+  EXPECT_EQ(20, file.GetPosition());
  251
+  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  252
+  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  253
+  EXPECT_EQ(-100, file.Seek(-100, SEEK_SET));
  254
+  file.Close();
  255
+
  256
+  /* /testsymlink -> testdir/reffile.txt */
  257
+  strpathinrar = itemlist[2]->GetPath();
  258
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testsymlink", true));
  259
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  260
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFLNK);
  261
+
  262
+  /*
  263
+   * FIXME: Reading symlinks in RARs is currently broken. It takes a long time
  264
+   * to read them and they produce erroneous results. The expected result is
  265
+   * the target paths of the symlinks.
  266
+   */
  267
+  ASSERT_TRUE(file.Open(strpathinrar));
  268
+  EXPECT_EQ(19, file.GetLength());
  269
+  file.Close();
  270
+
  271
+  /* /testsymlinksubdir -> testdir/testsubdir/reffile.txt */
  272
+  strpathinrar = itemlist[3]->GetPath();
  273
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testsymlinksubdir", true));
  274
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  275
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFLNK);
  276
+
  277
+  ASSERT_TRUE(file.Open(strpathinrar));
  278
+  EXPECT_EQ(30, file.GetLength());
  279
+  file.Close();
  280
+
  281
+  /* /testdir/ */
  282
+  strpathinrar = itemlist[0]->GetPath();
  283
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/", true));
  284
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  285
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFDIR);
  286
+
  287
+  itemlist.Clear();
  288
+  ASSERT_TRUE(XFILE::CDirectory::GetDirectory(strpathinrar, itemlist));
  289
+  itemlist.Sort(SORT_METHOD_FULLPATH, SortOrderAscending);
  290
+
  291
+  /* /testdir/reffile.txt */
  292
+  strpathinrar = itemlist[1]->GetPath();
  293
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/reffile.txt",
  294
+                                    true));
  295
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  296
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFREG);
  297
+
  298
+  ASSERT_TRUE(file.Open(strpathinrar));
  299
+  EXPECT_EQ(0, file.GetPosition());
  300
+  EXPECT_EQ(1616, file.GetLength());
  301
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  302
+  file.Flush();
  303
+  EXPECT_EQ(20, file.GetPosition());
  304
+  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  305
+  EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
  306
+  EXPECT_EQ(39, file.GetPosition());
  307
+  EXPECT_STREQ("an award-winning fr", buf);
  308
+  EXPECT_EQ(100, file.Seek(100));
  309
+  EXPECT_EQ(100, file.GetPosition());
  310
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  311
+  file.Flush();
  312
+  EXPECT_EQ(120, file.GetPosition());
  313
+  EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
  314
+  EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
  315
+  EXPECT_EQ(220, file.GetPosition());
  316
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  317
+  file.Flush();
  318
+  EXPECT_EQ(240, file.GetPosition());
  319
+  EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
  320
+  EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
  321
+  EXPECT_EQ(1596, file.GetPosition());
  322
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  323
+  file.Flush();
  324
+  EXPECT_EQ(1616, file.GetPosition());
  325
+  EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
  326
+  EXPECT_EQ(-1, file.Seek(100, SEEK_CUR));
  327
+  EXPECT_EQ(1616, file.GetPosition());
  328
+  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  329
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  330
+  file.Flush();
  331
+  EXPECT_EQ(20, file.GetPosition());
  332
+  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  333
+  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  334
+  EXPECT_EQ(-100, file.Seek(-100, SEEK_SET));
  335
+  file.Close();
  336
+
  337
+  /* /testdir/testemptysubdir */
  338
+  strpathinrar = itemlist[2]->GetPath();
  339
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testemptysubdir",
  340
+                                    true));
  341
+  /* TODO: Should this set the itemlist to an empty list instead? */
  342
+  EXPECT_FALSE(XFILE::CDirectory::GetDirectory(strpathinrar, itemlistemptydir));
  343
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  344
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFDIR);
  345
+
  346
+  /* FIXME: This directory appears a second time as a file */
  347
+  strpathinrar = itemlist[3]->GetPath();
  348
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testsubdir", true));
  349
+
  350
+  /* /testdir/testsymlink -> testsubdir/reffile.txt */
  351
+  strpathinrar = itemlist[4]->GetPath();
  352
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testsymlink",
  353
+                                    true));
  354
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  355
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFLNK);
  356
+
  357
+  ASSERT_TRUE(file.Open(strpathinrar));
  358
+  EXPECT_EQ(22, file.GetLength());
  359
+  file.Close();
  360
+
  361
+  /* /testdir/testsubdir/ */
  362
+  strpathinrar = itemlist[0]->GetPath();
  363
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testsubdir/",
  364
+                                    true));
  365
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  366
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFDIR);
  367
+
  368
+  itemlist.Clear();
  369
+  ASSERT_TRUE(XFILE::CDirectory::GetDirectory(strpathinrar, itemlist));
  370
+  itemlist.Sort(SORT_METHOD_FULLPATH, SortOrderAscending);
  371
+
  372
+  /* /testdir/testsubdir/reffile.txt */
  373
+  strpathinrar = itemlist[0]->GetPath();
  374
+  ASSERT_TRUE(StringUtils::EndsWith(strpathinrar,
  375
+                                    "/testdir/testsubdir/reffile.txt", true));
  376
+  EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
  377
+  EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFREG);
  378
+
  379
+  ASSERT_TRUE(file.Open(strpathinrar));
  380
+  EXPECT_EQ(0, file.GetPosition());
  381
+  EXPECT_EQ(1616, file.GetLength());
  382
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  383
+  file.Flush();
  384
+  EXPECT_EQ(20, file.GetPosition());
  385
+  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  386
+  EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
  387
+  EXPECT_EQ(39, file.GetPosition());
  388
+  EXPECT_STREQ("an award-winning fr", buf);
  389
+  EXPECT_EQ(100, file.Seek(100));
  390
+  EXPECT_EQ(100, file.GetPosition());
  391
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  392
+  file.Flush();
  393
+  EXPECT_EQ(120, file.GetPosition());
  394
+  EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
  395
+  EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
  396
+  EXPECT_EQ(220, file.GetPosition());
  397
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  398
+  file.Flush();
  399
+  EXPECT_EQ(240, file.GetPosition());
  400
+  EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
  401
+  EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
  402
+  EXPECT_EQ(1596, file.GetPosition());
  403
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  404
+  file.Flush();
  405
+  EXPECT_EQ(1616, file.GetPosition());
  406
+  EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
  407
+  EXPECT_EQ(-1, file.Seek(100, SEEK_CUR));
  408
+  EXPECT_EQ(1616, file.GetPosition());
  409
+  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  410
+  EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
  411
+  file.Flush();
  412
+  EXPECT_EQ(20, file.GetPosition());
  413
+  EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
  414
+  EXPECT_EQ(0, file.Seek(0, SEEK_SET));
  415
+  EXPECT_EQ(-100, file.Seek(-100, SEEK_SET));
  416
+  file.Close();
  417
+}
191 418
 #endif /*HAS_FILESYSTEM_RAR*/
BIN  xbmc/filesystem/test/refRARstored.rar
Binary file not shown

0 notes on commit 7efb0d7

Please sign in to comment.
Something went wrong with that request. Please try again.