Beispiel #1
0
  @Test
  public void testContentNameByteArrayArray() throws MalformedContentNameStringException {
    byte[][] arr = new byte[4][];
    arr[0] = baseName.getBytes();
    arr[1] = subName1.getBytes();
    arr[2] = document1.getBytes();
    System.out.println("Creating name from byte arrays.");
    ContentName name = new ContentName(3, arr);
    assertNotNull(name);
    System.out.println("Name: " + name);
    assertEquals(
        name,
        ContentName.fromURI(
            ContentName.SEPARATOR
                + baseName
                + ContentName.SEPARATOR
                + subName1
                + ContentName.SEPARATOR
                + document1));

    arr[3] = document3;
    ContentName name2 = new ContentName(arr);
    assertNotNull(name2);
    System.out.println("Name 2: " + name2);
    assertEquals(name2.count(), 4);
    assertEquals(name2.components().size(), 4);
    assert (DataUtils.arrayEquals(name2.component(0), arr[0]));
    assert (DataUtils.arrayEquals(name2.component(1), arr[1]));
    assert (DataUtils.arrayEquals(name2.component(2), arr[2]));
    assert (DataUtils.arrayEquals(name2.component(3), arr[3]));
  }
Beispiel #2
0
  @Test
  public void testGetFirstDigest() {
    Log.info(Log.FAC_TEST, "Starting testGetFirstDigest");

    long received = 0;
    byte[] bytes = new byte[1024];

    try {
      istream = new CCNInputStream(testName, readHandle);
    } catch (IOException e1) {
      Log.warning(Log.FAC_TEST, "failed to open stream for pipeline test: " + e1.getMessage());
      Assert.fail();
    }

    try {
      Assert.assertTrue(DataUtils.arrayEquals(firstDigest, istream.getFirstDigest()));
    } catch (IOException e3) {
      Log.warning(Log.FAC_TEST, "failed to get first digest for pipeline test:");
      Assert.fail();
    }
    try {
      istream.close();
    } catch (IOException e2) {
      Log.warning(Log.FAC_TEST, "failed to close stream for pipeline test: " + e2.getMessage());
      Assert.fail();
    }
    Log.info(Log.FAC_TEST, "start first segment digest " + DataUtils.printBytes(firstDigest));

    try {
      istream = new CCNInputStream(testName, readHandle);
    } catch (IOException e1) {
      Log.warning(Log.FAC_TEST, "failed to open stream for pipeline test: " + e1.getMessage());
      Assert.fail();
    }

    while (!istream.eof()) {
      try {
        received += istream.read(bytes);
      } catch (IOException e) {
        Log.warning(Log.FAC_TEST, "failed to read segments: " + e.getMessage());
        Assert.fail();
      }
    }
    Assert.assertTrue(received == bytesWritten);
    try {
      Assert.assertTrue(DataUtils.arrayEquals(firstDigest, istream.getFirstDigest()));
    } catch (IOException e) {
      Log.warning(Log.FAC_TEST, "failed to get first digest after reading in pipeline test:");
      Assert.fail();
    }
    Log.info(Log.FAC_TEST, "end first segment digest " + DataUtils.printBytes(firstDigest));

    Log.info(Log.FAC_TEST, "Completed testGetFirstDigest");
  }
Beispiel #3
0
  @Test
  public void testMultilevelString() throws MalformedContentNameStringException {
    // Test multilevel construction with Strings,
    // i.e. methods that take a parent and then additional components
    ContentName parent =
        ContentName.fromURI(ContentName.SEPARATOR + baseName + ContentName.SEPARATOR + subName1);
    assertNotNull(parent);
    assertEquals(parent.count(), 2);
    String childExtension = document1 + ContentName.SEPARATOR + document2;
    String[] childComps = new String[] {document1, document2};
    ContentName child = null;

    // URI case
    // Note: fromURI takes only one additional component, ignores rest
    child = ContentName.fromURI(parent, childExtension);
    System.out.println("Child is (URI): " + child);
    assertNotNull(child);
    assertEquals(child.count(), 3); // lose the last component
    assertTrue(parent.isPrefixOf(child));
    assertEquals(child.cut(document1.getBytes()), parent);
    assertTrue(DataUtils.arrayEquals(child.component(2), document1.getBytes()));

    child = ContentName.fromNative(parent, document1);
    System.out.println("Child is (native, one additional comp): " + child);
    assertNotNull(child);
    assertTrue(parent.isPrefixOf(child));
    assertEquals(child.count(), 3);
    assertEquals(child.cut(document1.getBytes()), parent);
    assertTrue(DataUtils.arrayEquals(child.component(2), document1.getBytes()));

    child = ContentName.fromNative(parent, childComps[0], childComps[1]);
    System.out.println("Child is (native): " + child);
    assertNotNull(child);
    ContentName child2 = ContentName.fromNative(parent, childComps);
    System.out.println("Child2 is (native): " + child2);
    assertNotNull(child2);
    assertEquals(child, child2);
    assertEquals(child2, child);
    assertTrue(parent.isPrefixOf(child));
    assertEquals(child.count(), 4);
    assertEquals(child.cut(document1.getBytes()), parent);
    assertTrue(DataUtils.arrayEquals(child.component(2), document1.getBytes()));
    assertTrue(DataUtils.arrayEquals(child.component(3), document2.getBytes()));
  }