summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2011-07-11 23:16:58 +0200
committerQt by Nokia <qt-info@nokia.com>2011-07-12 12:28:12 +0200
commitad35a41739c8e1fb6db62ed37b764448b2e59ece (patch)
tree1a5b688d19547362340c70a68647ca7b8e3f6d1c /tests
parent9fea02400c450b4b1a031506655d8c4b165cecd6 (diff)
Refactor QByteArray to allow for const data
Similar refactoring as done for QString. Make shared_null read-only, and add support for compile time generated QByteArrayData. Add support for properly reserving capacity. Change-Id: Ie4c41d4caac7b3b4bb1aef40c1c860a30b82edb8 Reviewed-on: http://codereview.qt.nokia.com/1484 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qbytearray/tst_qbytearray.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/tests/auto/qbytearray/tst_qbytearray.cpp b/tests/auto/qbytearray/tst_qbytearray.cpp
index e2f64b84f8..78b655419e 100644
--- a/tests/auto/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/qbytearray/tst_qbytearray.cpp
@@ -145,6 +145,8 @@ private slots:
void byteRefDetaching() const;
void reserve();
+
+ void literals();
};
tst_QByteArray::tst_QByteArray()
@@ -1527,14 +1529,38 @@ void tst_QByteArray::reserve()
QVERIFY(qba.capacity() == capacity);
char *data = qba.data();
- // FIXME count from 0 to make it fail
- for (int i = 1; i < capacity; i++) {
+ for (int i = 0; i < capacity; i++) {
qba.resize(i);
QVERIFY(capacity == qba.capacity());
QVERIFY(data == qba.data());
}
}
+void tst_QByteArray::literals()
+{
+#if defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU)
+ QByteArray str(QByteArrayLiteral("abcd"));
+
+ QVERIFY(str.length() == 4);
+ QVERIFY(str == "abcd");
+ QVERIFY(str.data_ptr()->ref == -1);
+ QVERIFY(str.data_ptr()->offset == 0);
+
+ const char *s = str.constData();
+ QByteArray str2 = str;
+ QVERIFY(str2.constData() == s);
+
+ // detach on non const access
+ QVERIFY(str.data() != s);
+
+ QVERIFY(str2.constData() == s);
+ QVERIFY(str2.data() != s);
+
+#else
+ QSKIP("Only tested on c++0x compliant compiler or gcc", SkipAll);
+#endif
+}
+
const char globalChar = '1';
QTEST_APPLESS_MAIN(tst_QByteArray)