summaryrefslogtreecommitdiffstats
path: root/tests/auto/v8/v8test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/v8/v8test.cpp')
-rw-r--r--tests/auto/v8/v8test.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/auto/v8/v8test.cpp b/tests/auto/v8/v8test.cpp
index 09410a6..2145acb 100644
--- a/tests/auto/v8/v8test.cpp
+++ b/tests/auto/v8/v8test.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include "v8test.h"
+#include <private/qcalculatehash_p.h>
using namespace v8;
@@ -1089,3 +1090,56 @@ cleanup:
ENDTEST();
}
+
+bool v8test_stringhashcomparison()
+{
+ BEGINTEST();
+
+ // Initialize V8 random seed for string hashing
+ HandleScope handle_scope;
+ Persistent<Context> context = Context::New();
+ Context::Scope context_scope(context);
+
+ quint32 hash1;
+ uint32_t hash2;
+ int length, rand;
+
+ const char* text;
+ QString qtext;
+
+ char textRand[HashedString::kMaxHashCalcLength + 1];
+ QString qtextRand;
+
+ text = "tipli";
+ qtext = QString(text);
+ length = strlen(text);
+
+ hash1 = calculateHash((uint8_t*)text, length) >> HashedString::kHashShift;
+ hash2 = String::ComputeHash((char*)text, length);
+ VERIFY(hash1 == hash2);
+
+ hash1 = calculateHash<quint16>((quint16*)qtext.constData(), length) >> HashedString::kHashShift;
+ hash2 = String::ComputeHash((uint16_t*)qtext.constData(), length);
+ VERIFY(hash1 == hash2);
+
+ // Check V8 trivial hash
+ length = HashedString::kMaxHashCalcLength + 1;
+ for (int i = 0; i < length; i++) {
+ rand = qrand() % 255 + 1;
+ textRand[i] = (char)rand;
+ }
+ qtextRand = QString(textRand);
+
+ hash1 = calculateHash((uint8_t*)textRand, length) >> HashedString::kHashShift;
+ hash2 = String::ComputeHash((char*)textRand, length);
+ VERIFY(hash1 == hash2);
+
+ hash1 = calculateHash<quint16>((quint16*)qtextRand.constData(), length) >> HashedString::kHashShift;
+ hash2 = String::ComputeHash((uint16_t*)qtextRand.constData(), length);
+ VERIFY(hash1 == hash2);
+
+cleanup:
+ context.Dispose();
+
+ ENDTEST();
+}