Пример #1
0
  @Test
  public void testFormatAddressJumpLocal2() {
    labels.newInstruction(
        new AssemblyInstruction("", 99, "", "blah", Collections.<String>emptyList(), "", labels));
    labels.newInstruction(
        new AssemblyInstruction(
            "anno", 65534, "mod", "jne", asList("0x0000000000000100"), "", labels));
    labels.newInstruction(
        new AssemblyInstruction(
            "anno", 65535, "mod", "jne", asList("0x0000000000001000"), "", labels));

    sb.setLength(0);
    labels.formatAddress(256, sb);
    assertEquals("0x0000000000000100", sb.toString());
    sb.setLength(0);
    labels.formatAddress(4096, sb);
    assertEquals("0x0000000000001000", sb.toString());

    labels.buildLabels();

    sb.setLength(0);
    labels.formatAddress(256, sb);
    assertEquals("             L0000", sb.toString());
    sb.setLength(0);
    labels.formatAddress(4096, sb);
    assertEquals("             L0001", sb.toString());
    sb.setLength(0);
    labels.formatAddress(65535, sb);
    assertEquals("0x000000000000ffff", sb.toString());
  }
Пример #2
0
 @Test
 public void testEncodeWithPercent() {
   StringBuilder buf = new StringBuilder();
   RFC2231.percentEscape(buf, "foo");
   assertEquals("foo", buf.toString());
   buf.setLength(0);
   RFC2231.percentEscape(buf, "foo bar");
   assertEquals("foo%20bar", buf.toString());
   buf.setLength(0);
   RFC2231.percentEscape(buf, "R\u00e9sultat d'Activit\u00e9 (;provisoire/draft).");
   assertEquals("R%C3%A9sultat%20d%27Activit%C3%A9%20%28%3Bprovisoire/draft%29.", buf.toString());
 }
Пример #3
0
  @Test
  public void testFormatAddressNotJump2() {
    labels.newInstruction(
        new AssemblyInstruction("anno", 65535, "mod", "jjj", asList("1", "2"), "", labels));

    sb.setLength(0);
    labels.formatAddress(65535, sb);
    assertEquals("0x000000000000ffff", sb.toString());

    labels.buildLabels();

    sb.setLength(0);
    labels.formatAddress(65535, sb);
    assertEquals("0x000000000000ffff", sb.toString());
  }
Пример #4
0
  public static String randomString(String fldName, int length) {

    if (fldName.length() >= length) {
      return fldName.substring(0, length);
    }

    sb.setLength(0);
    sb.append(fldName);
    for (int i = fldName.length(); i < length; i++) {
      sb.append(chars.charAt(random.nextInt(chars.length())));
    }
    return sb.toString();
  }
  @Test
  public void formatTo_usesCachedMessageString() throws Exception {
    final StringBuilder charSequence = new StringBuilder("initial value");
    final ObjectMessage message = new ObjectMessage(charSequence);
    assertEquals("initial value", message.getFormattedMessage());

    charSequence.setLength(0);
    charSequence.append("different value");

    final StringBuilder result = new StringBuilder();
    message.formatTo(result);
    assertEquals("initial value", result.toString());
  }
Пример #6
0
  @Test
  public void testFormatEmpty() {
    final AssemblyInstruction localJump =
        new AssemblyInstruction(
            null, 65535, null, "jne", asList("0x000000000000ffff"), null, labels);

    sb.setLength(0);
    labels.formatAddress(65535, sb);
    assertEquals("0x000000000000ffff", sb.toString());
    sb.setLength(0);
    labels.formatOperands(localJump, sb);
    assertEquals(" 0x000000000000ffff", sb.toString());

    labels.buildLabels();

    sb.setLength(0);
    labels.formatAddress(65535, sb);
    assertEquals("0x000000000000ffff", sb.toString());
    sb.setLength(0);
    labels.formatOperands(localJump, sb);
    assertEquals(" 0x000000000000ffff", sb.toString());
  }
Пример #7
0
  @Test
  public void testFormatNoOperands() {
    final AssemblyInstruction noOps =
        new AssemblyInstruction(
            null, 65535, null, "jne", Collections.<String>emptyList(), null, labels);

    sb.setLength(0);
    labels.formatAddress(65535, sb);
    assertEquals("0x000000000000ffff", sb.toString());
    sb.setLength(0);
    labels.formatOperands(noOps, sb);
    assertTrue(sb.toString().isEmpty());

    labels.newInstruction(noOps);
    labels.buildLabels();

    sb.setLength(0);
    labels.formatAddress(65535, sb);
    assertEquals("0x000000000000ffff", sb.toString());
    sb.setLength(0);
    labels.formatOperands(noOps, sb);
    assertTrue(sb.toString().isEmpty());
  }
Пример #8
0
  /*
     This is a copy of buildDeterministicValue() from core:com.yahoo.ycsb.workloads.CoreWorkload.java.
     That method is neither public nor static so we need a copy.
  */
  private String buildDeterministicValue(String key, String fieldkey) {
    int size = FIELD_LENGTH;
    StringBuilder sb = new StringBuilder(size);
    sb.append(key);
    sb.append(':');
    sb.append(fieldkey);
    while (sb.length() < size) {
      sb.append(':');
      sb.append(sb.toString().hashCode());
    }
    sb.setLength(size);

    return sb.toString();
  }
  @Test
  public void testPutAndRemove()
      throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
    String TMP = System.getProperty("java.io.tmpdir");
    File file = new File(TMP + "/shm-remove-test");
    file.delete();
    file.deleteOnExit();
    int entries = 100 * 1000;
    SharedHashMap<CharSequence, CharSequence> map =
        new SharedHashMapBuilder()
            .entries(entries)
            .minSegments(16)
            .entrySize(32)
            .putReturnsNull(true)
            .removeReturnsNull(true)
            .create(file, CharSequence.class, CharSequence.class);
    StringBuilder key = new StringBuilder();
    StringBuilder value = new StringBuilder();
    StringBuilder value2 = new StringBuilder();
    for (int j = 1; j <= 3; j++) {
      for (int i = 0; i < entries; i++) {
        key.setLength(0);
        key.append("user:"******"value:").append(i);
        //                System.out.println(key);
        assertNull(map.getUsing(key, value));
        assertNull(map.put(key, value));
        assertNotNull(map.getUsing(key, value2));
        assertEquals(value.toString(), value2.toString());
        assertNull(map.remove(key));
        assertNull(map.getUsing(key, value));
      }
    }

    map.close();
  }
Пример #10
0
  void prepareQueries(File google, File yandex) throws IOException {
    StringBuilder sb = new StringBuilder();

    sb.append("url: http://google.com\n");
    sb.append("method: GET\n");
    sb.append("cookie: name=value\n");
    sb.append("param: name=value\n");
    IOUtil.saveString(sb.toString(), google);

    sb.setLength(0);
    sb.append("url: http://yandex.ru\n");
    sb.append("method: GET\n");
    sb.append("cookie: name=value\n");
    sb.append("param: name=value\n");
    IOUtil.saveString(sb.toString(), yandex);
  }
 private CharSequence getUserCharSequence(int i) {
   sb.setLength(0);
   sb.append("u:");
   sb.append(i * 9876); // test 10 digit user numbers.
   return sb;
 }