01: /*
02: * HexBlobFormatterTest.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.storage;
13:
14: import java.io.ByteArrayOutputStream;
15: import junit.framework.TestCase;
16:
17: /**
18: * @author support@sql-workbench.net
19: */
20: public class DefaultBlobFormatterTest extends TestCase {
21: public DefaultBlobFormatterTest(String testName) {
22: super (testName);
23: }
24:
25: public void testGetBlobLiteral() throws Exception {
26: DefaultBlobFormatter formatter = new DefaultBlobFormatter();
27: ByteArrayOutputStream b = new ByteArrayOutputStream();
28: b.write(255);
29: b.write(0);
30: b.write(16);
31: b.write(15);
32: byte[] blob = b.toByteArray();
33: String literal = formatter.getBlobLiteral(blob);
34:
35: assertEquals("Wrong literal created", "ff00100f", literal);
36:
37: formatter.setPrefix("0x");
38: formatter.setSuffix(null);
39: literal = formatter.getBlobLiteral(blob);
40: assertEquals("Wrong literal created", "0xff00100f", literal);
41:
42: formatter.setPrefix("'");
43: formatter.setSuffix("'");
44: literal = formatter.getBlobLiteral(blob);
45: assertEquals("Wrong literal created", "'ff00100f'", literal);
46:
47: formatter.setPrefix("X'");
48: formatter.setSuffix("'");
49: formatter.setUseUpperCase(true);
50: literal = formatter.getBlobLiteral(blob);
51: assertEquals("Wrong literal created", "X'FF00100F'", literal);
52:
53: formatter.setUseUpperCase(true);
54: formatter.setPrefix("to_lob(utl_raw.cast_to_raw('0x");
55: formatter.setSuffix("'))");
56: literal = formatter.getBlobLiteral(blob);
57: assertEquals("Wrong literal created",
58: "to_lob(utl_raw.cast_to_raw('0xFF00100F'))", literal);
59:
60: formatter.setUseUpperCase(false);
61: formatter.setPrefix(null);
62: formatter.setSuffix(null);
63: formatter.setLiteralType(BlobLiteralType.octal);
64: literal = formatter.getBlobLiteral(blob);
65: assertEquals("Wrong literal created", "\\377\\000\\020\\017",
66: literal);
67: }
68: }
|