1//===- DirIteratorTest.cpp ------------------------------------------------===//
2//
3//                     The MCLinker Project
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9#include "mcld/Support/Directory.h"
10#include "DirIteratorTest.h"
11#include <errno.h>
12
13using namespace mcld;
14using namespace mcld::sys::fs;
15using namespace mcldtest;
16
17// Constructor can do set-up work for all test here.
18DirIteratorTest::DirIteratorTest() {
19  // FIXME:Some bugs modifies the global value "errno" to non-zero.
20  //      This makes readir() failed when daily build system runs unittest
21  //      Remove this after fixing those bugs
22  errno = 0;
23
24  // create testee. modify it if need
25  m_pDir = new mcld::sys::fs::Directory(".");
26}
27
28// Destructor can do clean-up work that doesn't throw exceptions here.
29DirIteratorTest::~DirIteratorTest() {
30  delete m_pDir;
31}
32
33// SetUp() will be called immediately before each test.
34void DirIteratorTest::SetUp() {
35}
36
37// TearDown() will be called immediately after each test.
38void DirIteratorTest::TearDown() {
39}
40
41//==========================================================================//
42// Testcases
43//
44TEST_F(DirIteratorTest, open_dir) {
45  ASSERT_TRUE(m_pDir->isGood());
46
47  Directory::iterator entry = m_pDir->begin();
48  Directory::iterator enEnd = m_pDir->end();
49
50  size_t size = 0;
51  while (entry != enEnd) {
52    if (0 != entry.path()) {
53      size = entry.path()->native().size();
54      ASSERT_TRUE(size != 0);
55    }
56
57    ++entry;
58  }
59}
60