public void TestCISPrep() { for (int i = 0; i < (TestData.conformanceTestCases.Length); i++) { TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i]; String src = testCase.input; Exception expected = testCase.expected; String expectedDest = testCase.output; try { byte[] dest = NFS4StringPrep.CISPrepare(Encoding.UTF8.GetBytes(src)); String destString = Encoding.UTF8.GetString(dest); if (!expectedDest.Equals(destString, StringComparison.OrdinalIgnoreCase)) { Errln("Did not get the expected output for nfs4_cis_prep at index " + i); } } catch (Exception e) { if (expected != null && !expected.Equals(e)) { Errln("Did not get the expected exception: " + e.ToString()); } } } }
public void TestNFS4MixedPrep() { for (int i = 0; i < mixed_prep_data.Length; i++) { try { String src = mixed_prep_data[i]; byte[] dest = NFS4StringPrep.MixedPrepare(Encoding.UTF8.GetBytes(src)); String destString = Encoding.UTF8.GetString(dest); int destIndex = destString.IndexOf('@'); if (destIndex < 0) { Errln("Delimiter @ disappeared from the output!"); } } catch (Exception e) { Errln("mixed_prepare for string: " + mixed_prep_data[i] + " failed with " + e.ToString()); } } /* test the error condition */ { String src = "*****@*****.**"; try { byte[] dest = NFS4StringPrep.MixedPrepare(Encoding.UTF8.GetBytes(src)); if (dest != null) { Errln("Did not get the expected exception"); } } catch (Exception e) { Logln("mixed_prepare for string: " + src + " passed with " + e.ToString()); } } }
public void TestCSPrep() { // Checking for bidi is turned off String src = "\uC138\uACC4\uC758\uBAA8\uB4E0\uC0AC\uB78C\uB4E4\uC774\u0644\u064A\u0647\uD55C\uAD6D\uC5B4\uB97C\uC774\uD574\uD55C\uB2E4\uBA74"; try { NFS4StringPrep.CSPrepare(Encoding.UTF8.GetBytes(src), false); } catch (Exception e) { Errln("Got unexpected exception: " + e.ToString()); } // normalization is turned off try { src = "www.\u00E0\u00B3\u00AF.com"; byte[] dest = NFS4StringPrep.CSPrepare(Encoding.UTF8.GetBytes(src), false); String destStr = Encoding.UTF8.GetString(dest); if (!src.Equals(destStr)) { Errln("Did not get expected output. Expected: " + Prettify(src) + " Got: " + Prettify(destStr)); } } catch (Exception e) { Errln("Got unexpected exception: " + e.ToString()); } // test case insensitive string try { src = "THISISATEST"; byte[] dest = NFS4StringPrep.CSPrepare(Encoding.UTF8.GetBytes(src), false); String destStr = Encoding.UTF8.GetString(dest); if (!src.ToLowerInvariant().Equals(destStr)) { Errln("Did not get expected output. Expected: " + Prettify(src) + " Got: " + Prettify(destStr)); } } catch (Exception e) { Errln("Got unexpected exception: " + e.ToString()); } // test case sensitive string try { src = "THISISATEST"; byte[] dest = NFS4StringPrep.CSPrepare(Encoding.UTF8.GetBytes(src), true); String destStr = Encoding.UTF8.GetString(dest); if (!src.Equals(destStr)) { Errln("Did not get expected output. Expected: " + Prettify(src) + " Got: " + Prettify(destStr)); } } catch (Exception e) { Errln("Got unexpected exception: " + e.ToString()); } }