|
| 1 | +// Copyright (c) 2012 Jeff Ichnowski |
| 2 | +// All rights reserved. |
| 3 | +// |
| 4 | +// Redistribution and use in source and binary forms, with or without |
| 5 | +// modification, are permitted provided that the following conditions |
| 6 | +// are met: |
| 7 | +// |
| 8 | +// * Redistributions of source code must retain the above |
| 9 | +// copyright notice, this list of conditions and the following |
| 10 | +// disclaimer. |
| 11 | +// |
| 12 | +// * Redistributions in binary form must reproduce the above |
| 13 | +// copyright notice, this list of conditions and the following |
| 14 | +// disclaimer in the documentation and/or other materials |
| 15 | +// provided with the distribution. |
| 16 | +// |
| 17 | +// * Neither the name of the OWASP nor the names of its |
| 18 | +// contributors may be used to endorse or promote products |
| 19 | +// derived from this software without specific prior written |
| 20 | +// permission. |
| 21 | +// |
| 22 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 | +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 | +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 25 | +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 26 | +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 27 | +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 28 | +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 29 | +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 30 | +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 31 | +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 32 | +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 33 | +// OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 | + |
| 35 | +package org.owasp.encoder; |
| 36 | + |
| 37 | +import junit.framework.Test; |
| 38 | +import junit.framework.TestCase; |
| 39 | +import junit.framework.TestSuite; |
| 40 | + |
| 41 | +/** |
| 42 | + * KMLEncoderTest -- test suite for the KMLEncoder. |
| 43 | + * |
| 44 | + * @author cnsgithub |
| 45 | + */ |
| 46 | +public class KMLEncoderTest extends TestCase { |
| 47 | + |
| 48 | + public static Test suite() { |
| 49 | + TestSuite suite = new TestSuite(); |
| 50 | + EncoderTestSuiteBuilder builder = new EncoderTestSuiteBuilder(new KMLEncoder(), "-safe-", "-&-") |
| 51 | + .encode("<strike>foo & bar</strike>", "<strike>foo & bar</strike>") |
| 52 | + .encode("invalid-control-characters", " b ", "\0b\26") |
| 53 | + .encode("valid-surrogate-pair", "\ud800\udc00", "\ud800\udc00") |
| 54 | + .encode("missing-low-surrogate", " ", "\ud800") |
| 55 | + .encode("missing-high-surrogate", " ", "\udc00") |
| 56 | + .encode("valid-upper-char", "\ufffd", "\ufffd") |
| 57 | + .encode("invalid-upper-char", " ", "\uffff") |
| 58 | + .invalid(0, 0x1f) |
| 59 | + .valid("\t\r\n") |
| 60 | + .valid(' ', Character.MAX_CODE_POINT) |
| 61 | + .invalid(0x7f, 0x9f) |
| 62 | + .valid("\u0085") |
| 63 | + .invalid(Character.MIN_SURROGATE, Character.MAX_SURROGATE) |
| 64 | + .invalid(0xfdd0, 0xfdef) |
| 65 | + .invalid(0xfffe, 0xffff) |
| 66 | + .invalid(0x1fffe, 0x1ffff) |
| 67 | + .invalid(0x2fffe, 0x2ffff) |
| 68 | + .invalid(0x3fffe, 0x3ffff) |
| 69 | + .invalid(0x4fffe, 0x4ffff) |
| 70 | + .invalid(0x5fffe, 0x5ffff) |
| 71 | + .invalid(0x6fffe, 0x6ffff) |
| 72 | + .invalid(0x7fffe, 0x7ffff) |
| 73 | + .invalid(0x8fffe, 0x8ffff) |
| 74 | + .invalid(0x9fffe, 0x9ffff) |
| 75 | + .invalid(0xafffe, 0xaffff) |
| 76 | + .invalid(0xbfffe, 0xbffff) |
| 77 | + .invalid(0xcfffe, 0xcffff) |
| 78 | + .invalid(0xdfffe, 0xdffff) |
| 79 | + .invalid(0xefffe, 0xeffff) |
| 80 | + .invalid(0xffffe, 0xfffff) |
| 81 | + .invalid(0x10fffe, 0x10ffff); |
| 82 | + |
| 83 | + builder.encoded("&><\'\"") |
| 84 | + .encode("'", "\'") |
| 85 | + .encode(""", "\"") |
| 86 | + .encode("safe", "safe"); |
| 87 | + |
| 88 | + suite.addTest(builder.validSuite().invalidSuite(XMLEncoder.INVALID_CHARACTER_REPLACEMENT).encodedSuite().build()); |
| 89 | + return suite; |
| 90 | + } |
| 91 | + |
| 92 | +} |
| 93 | + |
0 commit comments