예제 #1
0
int main()
{
    Directory* directory = new(Directory);
    directory->setName(&directory->ifile, "directory");

    Regular* regular = new(Regular);
    regular->setName(&regular->ifile, "file1");
    regular->setContent(&regular->ifile, "this is file1.");
    directory->add(&directory->ifile, &regular->ifile);

    regular = new(Regular);
    regular->setName(&regular->ifile, "file2");
    regular->setContent(&regular->ifile, "this is file2.");
    directory->add(&directory->ifile, &regular->ifile);

    printf("directory name: %s\n", directory->getName(&directory->ifile));

    IFile* file = directory->getChild(&directory->ifile, "file1");
    regular = container_of(file, Regular, ifile);
    printf("file name: %s, file content: %s\n",
           regular->getName(&regular->ifile),
           regular->getContent(&regular->ifile));

    file = directory->getChild(&directory->ifile, "file2");
    regular = container_of(file, Regular, ifile);
    printf("file name: %s, file content: %s\n",
           regular->getName(&regular->ifile),
           regular->getContent(&regular->ifile));

    delete(Directory, directory);
    return 0;
}
예제 #2
0
TEST(UnfixturedDirectoryTest, ObjectsAreDeletedWhenDirectoryIsDeleted)
{
    Directory<std::string, TrackableObject> *directory = new Directory<std::string, TrackableObject>("Directory");
    TrackableObject *t1 = new TrackableObject();
    ASSERT_EQ(TrackableObject::getInstances(), 1);
    directory->add("key", t1, 100);
    ASSERT_EQ(TrackableObject::getInstances(), 1) << "Directory copied / deleted object";
    delete directory;
    ASSERT_EQ(TrackableObject::getInstances(), 0) << "Directory did not delete Object when it was deleted";
}
예제 #3
0
TEST(UnfixturedDirectoryTest, QSPObjectsAreDeletedIfDirectoryIsDeleted)
{
    Directory<std::string, TrackableObject> *directory = new Directory<std::string, TrackableObject>("Directory");
    {
        std::shared_ptr<TrackableObject> tp = std::shared_ptr<TrackableObject>(new TrackableObject());
        ASSERT_EQ(TrackableObject::getInstances(), 1);
        directory->add("key", tp, 100);
    }
    delete directory;
    ASSERT_EQ(TrackableObject::getInstances(), 0) << "Directory did not delete Object";
}
예제 #4
0
TEST(UnfixturedDirectoryTest, ObjectsAreDeletedByDirectoryAfterTtl)
{
    Directory<std::string, TrackableObject> *directory = new Directory<std::string, TrackableObject>("Directory");
    TrackableObject *t1 = new TrackableObject();
    ASSERT_EQ(TrackableObject::getInstances(), 1);
    directory->add("key", t1, 100);
    ASSERT_EQ(TrackableObject::getInstances(), 1) << "Directory copied / deleted object";
    std::this_thread::sleep_for(std::chrono::milliseconds(200));
    ASSERT_EQ(TrackableObject::getInstances(), 0) << "Directory did not delete Object";
    delete directory;
}
예제 #5
0
int main() {
    
    // Model as if there are these four kinds
    // of position in the problem:
    Position boss("Boss", 3141.59);
    Position pointyHair("Pointy Hair", 271.83);
    Position techie("Techie", 14142.13);
    Position peon("Peonissimo", 34.79);
    
    // 
    Directory d;
    d.add("Marilyn", 123, 4567, boss);
    //d.add("John", 321, 7654, boss);
    //d.add("Bob", 234, 9876, boss);
    cout << d << endl;
    Directory d2 = d;	// What function is being used.
    d2.add("Gallagher", 111, 2222, techie);
    cout << d2 << endl;
    Directory d3;
    d3 = d2;
    cout << d3 << endl;

    cout << d3["Marilyn"];
}