15460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===- DirIteratorTest.cpp ------------------------------------------------===//
25460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
35460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//                     The MCLinker Project
45460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
55460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// This file is distributed under the University of Illinois Open Source
65460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// License. See LICENSE.TXT for details.
75460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
85460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===//
937b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/Support/Directory.h"
105460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include "DirIteratorTest.h"
11f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines#include <errno.h>
125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
135460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaousing namespace mcld;
145460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaousing namespace mcld::sys::fs;
155460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaousing namespace mcldtest;
165460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// Constructor can do set-up work for all test here.
1837b74a387bb3993387029859c2d9d051c41c724eStephen HinesDirIteratorTest::DirIteratorTest() {
1937b74a387bb3993387029859c2d9d051c41c724eStephen Hines  // FIXME:Some bugs modifies the global value "errno" to non-zero.
205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  //      This makes readir() failed when daily build system runs unittest
215460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  //      Remove this after fixing those bugs
225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  errno = 0;
235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  // create testee. modify it if need
255460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  m_pDir = new mcld::sys::fs::Directory(".");
265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao}
275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// Destructor can do clean-up work that doesn't throw exceptions here.
2937b74a387bb3993387029859c2d9d051c41c724eStephen HinesDirIteratorTest::~DirIteratorTest() {
305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  delete m_pDir;
315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao}
325460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
335460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// SetUp() will be called immediately before each test.
3437b74a387bb3993387029859c2d9d051c41c724eStephen Hinesvoid DirIteratorTest::SetUp() {
355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao}
365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// TearDown() will be called immediately after each test.
3837b74a387bb3993387029859c2d9d051c41c724eStephen Hinesvoid DirIteratorTest::TearDown() {
395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao}
405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
415460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//==========================================================================//
425460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// Testcases
435460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
4437b74a387bb3993387029859c2d9d051c41c724eStephen HinesTEST_F(DirIteratorTest, open_dir) {
4537b74a387bb3993387029859c2d9d051c41c724eStephen Hines  ASSERT_TRUE(m_pDir->isGood());
465460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  Directory::iterator entry = m_pDir->begin();
485460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  Directory::iterator enEnd = m_pDir->end();
495460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
505460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  size_t size = 0;
5137b74a387bb3993387029859c2d9d051c41c724eStephen Hines  while (entry != enEnd) {
522bf3f881f79c4d883f379e63725e788c310739a3Pirama Arumuga Nainar    if (0 != entry.path()) {
535460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao      size = entry.path()->native().size();
542bf3f881f79c4d883f379e63725e788c310739a3Pirama Arumuga Nainar      ASSERT_TRUE(size != 0);
552bf3f881f79c4d883f379e63725e788c310739a3Pirama Arumuga Nainar    }
565460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
575460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao    ++entry;
585460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  }
595460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao}
60