# test-cdata.rb -- translated to ruby from Paolo Casarini's test-cdata.c # # Copyright (C) 2001 Paolo Casarini # Copyright (C) 2001 Tobias Peters # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this library; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. require "gdome" def dot $stdout.print(".") $stdout.flush end def test_cdata1(doc) ret = true txt = doc.createTextNode("Initial String") # /* Test Text.length */ if (txt.length != 14) $stderr.print("\nText.length, wrong") ret = false end # /* Test Text.data */ if (txt.data != "Initial String") $stderr.print("\nText.data, wrong") ret = false end # /* Test Text.set_data */ txt.data = "0123456789" if (txt.data != "0123456789") $stderr.print("\nText.set_data, wrong") ret = false end # /* Test Text.substringData() */ if (txt.substringData(3,3) != "345") $stderr.print("\nText.substringData(3,3), wrong") ret = false end if (txt.substringData(4,10) != "456789") $stderr.print("Text.substringData(4,10), wrong") ret = false end # /* Test Text.appendData() */ txt.appendData("ABCDEF") if (txt.data != "0123456789ABCDEF") $stderr.print("\nText.append_data, wrong") ret = false end # /* Test Text.insertData() */ txt.insertData(3, "X") if (txt.data != "012X3456789ABCDEF") $stderr.print("\nText.insert_data, wrong") ret = false end # /* Test Text.deleteData() */ txt.deleteData(3,1) if (txt.data != "0123456789ABCDEF") $stderr.print("\nText.deleteData(3,1), wrong") ret = false end txt.deleteData(10,8) if (txt.data != "0123456789") $stderr.print("\nText.deleteData(10,8), wrong") ret = false end # /* Test Text.replaceData() */ txt.replaceData(0,3, "ABC") if (txt.data != "ABC3456789") $stderr.print("\nText.replaceData(0,3,\"ABC\"), wrong") ret = false end txt.replaceData(4,3, "XXXXXX") if (txt.data != "ABC3XXXXXX789") $stderr.print("\nText.replaceData(4,3, \"XXXXXX\"), wrong") ret = false end txt.replaceData(12,1, "XABCDEF") if (txt.data != "ABC3XXXXXX78XABCDEF") $stderr.print('\nText.replaceData(12,1, "XABCDEF"), wrong') ret = false end dot() print("test_text1\n") ret end domImpl = Dom::implementation domdoc = domImpl.createDocument(nil, "TEST", nil) test_cdata1(domdoc)