[education/rkward] rkward: Add test for new encoding functions

Thomas Friedrichsmeier null at kde.org
Thu Apr 18 17:40:15 BST 2024


Git commit ae73e6b2da35cbbc5a5fce2961871296fb88182e by Thomas Friedrichsmeier.
Committed on 18/04/2024 at 16:38.
Pushed by tfry into branch 'master'.

Add test for new encoding functions

M  +23   -0    rkward/autotests/core_test.cpp
M  +1    -0    rkward/rbackend/rkrbackend.cpp
M  +0    -2    rkward/rbackend/rkrbackendprotocol_shared.cpp
M  +1    -0    rkward/rbackend/rkrsupport.cpp

https://invent.kde.org/education/rkward/-/commit/ae73e6b2da35cbbc5a5fce2961871296fb88182e

diff --git a/rkward/autotests/core_test.cpp b/rkward/autotests/core_test.cpp
index 4fb1efeaf..30a726216 100644
--- a/rkward/autotests/core_test.cpp
+++ b/rkward/autotests/core_test.cpp
@@ -177,6 +177,29 @@ private Q_SLOTS:
 		});
 	}
 
+	void encodingTest() {
+		QString test_string = QStringLiteral("français");
+		RInterface::issueCommand(QStringLiteral("x <- ") + RObject::rQuote(test_string), RCommand::User);
+		auto c = new RCommand(QStringLiteral("cat(x); y <- \"fran\\xE7ais\"; Encoding(y) <- \"latin1\"; list(x==y, x, y)"), RCommand::GetStructuredData | RCommand::App);
+		runCommandWithTimeout(c, nullptr, [test_string](RCommand *command) {
+			QCOMPARE(command->output(), test_string);
+			QCOMPARE(command->getDataType(), RData::StructureVector);
+			QCOMPARE(command->getDataLength(), 3);
+			QVERIFY(command->structureVector().value(0)->intVector().value(0, 0) > 0);
+			QCOMPARE(command->structureVector().value(1)->stringVector().value(0), test_string);
+			QCOMPARE(command->structureVector().value(2)->stringVector().value(0), test_string);
+		});
+		// This one is to test that we don't screw up on strings exceeding the conversion buffer size
+		c = new RCommand(QStringLiteral("x <- paste0(rep(x, 2000), collapse=\",\"); cat(x); x"), RCommand::GetStringVector | RCommand::App);
+		runCommandWithTimeout(c, nullptr, [test_string](RCommand *command) {
+			QCOMPARE(command->output().count(test_string), 2000);
+			QCOMPARE(command->getDataType(), RData::StringVector);
+			QCOMPARE(command->getDataLength(), 1);
+			QCOMPARE(command->stringVector().value(0).count(test_string), 2000);
+		});
+		RInterface::issueCommand(QStringLiteral("rm(x); rm(y)"), RCommand::User);
+	}
+
 	void irregularShortNameTest() {
 		QVERIFY(RObject::irregularShortName("0x"));
 		QVERIFY(RObject::irregularShortName(".1x"));
diff --git a/rkward/rbackend/rkrbackend.cpp b/rkward/rbackend/rkrbackend.cpp
index 890957a86..2f2fd609c 100644
--- a/rkward/rbackend/rkrbackend.cpp
+++ b/rkward/rbackend/rkrbackend.cpp
@@ -1594,6 +1594,7 @@ RCommandProxy * RKRBackend::handleRequest2(RBackendRequest* request, bool mayHan
 
 	{
 		QMutexLocker lock (&all_current_commands_mutex);
+		RK_ASSERT(command != current_command);
 		all_current_commands.append (command);
 		current_command = command;
 	}
diff --git a/rkward/rbackend/rkrbackendprotocol_shared.cpp b/rkward/rbackend/rkrbackendprotocol_shared.cpp
index b99c220cb..2a582ca8b 100644
--- a/rkward/rbackend/rkrbackendprotocol_shared.cpp
+++ b/rkward/rbackend/rkrbackendprotocol_shared.cpp
@@ -20,8 +20,6 @@ RCommandProxy::RCommandProxy (const QString &command, int type) {
 
 RCommandProxy::~RCommandProxy () {
 	RK_TRACE (RBACKEND);
-
-	RK_ASSERT ((type & RCommand::Internal) || (getDataType () == RData::NoData));
 }
 
 
diff --git a/rkward/rbackend/rkrsupport.cpp b/rkward/rbackend/rkrsupport.cpp
index a847d295c..9c549f0f9 100644
--- a/rkward/rbackend/rkrsupport.cpp
+++ b/rkward/rbackend/rkrsupport.cpp
@@ -422,6 +422,7 @@ QByteArray RKTextCodec::doConv(void *cd, const QByteArray &inp) {
 void *RKTextCodec::from_native = nullptr;
 void *RKTextCodec::to_native = nullptr;
 void RKTextCodec::reinit() {
+	// TODO: Detect if running in a UTF-8 locale, in which case all conversion can be omitted
 	if (from_native) {
 		Riconv_close(from_native);
 		Riconv_close(to_native);



More information about the rkward-tracker mailing list