Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drape/attribute_provider.cpp5
-rw-r--r--drape/attribute_provider.hpp2
-rw-r--r--drape/drape_tests/attribute_provides_tests.cpp199
-rw-r--r--drape/drape_tests/drape_tests.pro3
4 files changed, 204 insertions, 5 deletions
diff --git a/drape/attribute_provider.cpp b/drape/attribute_provider.cpp
index fbeb4827df..6c677ba7b6 100644
--- a/drape/attribute_provider.cpp
+++ b/drape/attribute_provider.cpp
@@ -4,7 +4,7 @@
#ifdef DEBUG
#define INIT_CHECK_INFO(x) m_checkInfo = vector<bool>((vector<bool>::size_type)(x), false);
#define CHECK_STREAMS CheckStreams()
- #define INIT_STREAM(x) InitStream((x))
+ #define INIT_STREAM(x) InitCheckStream((x))
#else
#include "../../base/macros.hpp"
#define INIT_CHECK_INFO(x) UNUSED_VALUE((x))
@@ -28,7 +28,6 @@ bool AttributeProvider::IsDataExists() const
uint16_t AttributeProvider::GetVertexCount() const
{
- CHECK_STREAMS;
return m_vertexCount;
}
@@ -85,7 +84,7 @@ void AttributeProvider::CheckStreams() const
("Not all streams initialized"));
}
-void AttributeProvider::InitStream(uint8_t streamIndex)
+void AttributeProvider::InitCheckStream(uint8_t streamIndex)
{
m_checkInfo[streamIndex] = true;
}
diff --git a/drape/attribute_provider.hpp b/drape/attribute_provider.hpp
index e95bd9808b..050629377c 100644
--- a/drape/attribute_provider.hpp
+++ b/drape/attribute_provider.hpp
@@ -35,7 +35,7 @@ private:
vector<AttributeStream> m_streams;
#ifdef DEBUG
void CheckStreams() const;
- void InitStream(uint8_t streamIndex);
+ void InitCheckStream(uint8_t streamIndex);
vector<bool> m_checkInfo;
#endif
};
diff --git a/drape/drape_tests/attribute_provides_tests.cpp b/drape/drape_tests/attribute_provides_tests.cpp
new file mode 100644
index 0000000000..a7d339effe
--- /dev/null
+++ b/drape/drape_tests/attribute_provides_tests.cpp
@@ -0,0 +1,199 @@
+#include "../../testing/testing.hpp"
+
+#include "../attribute_provider.hpp"
+
+#include <gmock/gmock.h>
+
+UNIT_TEST(InitStreamsTest)
+{
+ const int VERTEX_COUNT = 10;
+ AttributeProvider provider(3, VERTEX_COUNT);
+ float positions[2 * VERTEX_COUNT];
+ float depth[VERTEX_COUNT];
+ float normals[2 * VERTEX_COUNT];
+
+ for (int i = 0; i < VERTEX_COUNT; ++i)
+ {
+ positions[2 * i] = (float)i;
+ positions[(2 * i) + 1] = 0.0f;
+ depth[i] = (float)i;
+ normals[2 * i] = (float)i;
+ normals[(2 * i) + 1] = 0.0;
+ }
+
+ {
+ BindingInfo zeroStreamBinding(1);
+ BindingDecl & decl = zeroStreamBinding.GetBindingDecl(0);
+ decl.m_attributeName = "position";
+ decl.m_componentCount = 2;
+ decl.m_componentType = GLConst::GLFloatType;
+ decl.m_offset = 0;
+ decl.m_stride = 0;
+ provider.InitStream(0, zeroStreamBinding, ReferencePoiner<void>(positions));
+ }
+
+ {
+ BindingInfo firstStreamBinding(1);
+ BindingDecl & decl = firstStreamBinding.GetBindingDecl(0);
+ decl.m_attributeName = "depth";
+ decl.m_componentCount = 1;
+ decl.m_componentType = GLConst::GLFloatType;
+ decl.m_offset = 0;
+ decl.m_stride = 0;
+ provider.InitStream(1, firstStreamBinding, ReferencePoiner<void>(depth));
+ }
+
+ {
+ BindingInfo secondStreamBinding(1);
+ BindingDecl & decl = secondStreamBinding.GetBindingDecl(0);
+ decl.m_attributeName = "normal";
+ decl.m_componentCount = 2;
+ decl.m_componentType = GLConst::GLFloatType;
+ decl.m_offset = 0;
+ decl.m_stride = 0;
+ provider.InitStream(2, secondStreamBinding, ReferencePoiner<void>(normals));
+ }
+
+ TEST_EQUAL(provider.IsDataExists(), true, ());
+ TEST_EQUAL(provider.GetVertexCount(), 10, ());
+ TEST_EQUAL(provider.GetRawPointer(0), (void *)positions, ());
+ TEST_EQUAL(provider.GetRawPointer(1), (void *)depth, ());
+ TEST_EQUAL(provider.GetRawPointer(2), (void *)normals, ());
+
+ provider.Advance(1);
+
+ TEST_EQUAL(provider.IsDataExists(), true, ());
+ TEST_EQUAL(provider.GetVertexCount(), 9, ());
+ TEST_EQUAL(provider.GetRawPointer(0), (void *)(&positions[2]), ());
+ TEST_EQUAL(provider.GetRawPointer(1), (void *)(&depth[1]), ());
+ TEST_EQUAL(provider.GetRawPointer(2), (void *)(&normals[2]), ());
+
+ provider.Advance(9);
+ TEST_EQUAL(provider.IsDataExists(), false, ());
+ TEST_EQUAL(provider.GetVertexCount(), 0, ());
+}
+
+UNIT_TEST(InterleavedStreamTest)
+{
+ const int VERTEX_COUNT = 10;
+ AttributeProvider provider(1, 10);
+ float data[5 * VERTEX_COUNT];
+
+ for (int i = 0; i < VERTEX_COUNT; ++i)
+ {
+ data[(5 * i)] = (float)i;
+ data[(5 * i) + 1] = 0.0;
+ data[(5 * i) + 2] = (float)i;
+ data[(5 * i) + 3] = (float)i;
+ data[(5 * i) + 4] = 0.0;
+ }
+
+ BindingInfo binding(3);
+ {
+ BindingDecl & decl = binding.GetBindingDecl(0);
+ decl.m_attributeName = "position";
+ decl.m_componentCount = 2;
+ decl.m_componentType = GLConst::GLFloatType;
+ decl.m_offset = 0;
+ decl.m_stride = 5 * sizeof(float);
+ }
+ {
+ BindingDecl & decl = binding.GetBindingDecl(1);
+ decl.m_attributeName = "depth";
+ decl.m_componentCount = 1;
+ decl.m_componentType = GLConst::GLFloatType;
+ decl.m_offset = 2 * sizeof(float);
+ decl.m_stride = 5 * sizeof(float);
+ }
+ {
+ BindingDecl & decl = binding.GetBindingDecl(2);
+ decl.m_attributeName = "normal";
+ decl.m_componentCount = 2;
+ decl.m_componentType = GLConst::GLFloatType;
+ decl.m_offset = 3 * sizeof(float);
+ decl.m_stride = 5 * sizeof(float);
+ }
+
+ provider.InitStream(0, binding, ReferencePoiner<void>(data));
+
+ TEST_EQUAL(provider.IsDataExists(), true, ());
+ TEST_EQUAL(provider.GetVertexCount(), 10, ());
+ TEST_EQUAL(provider.GetRawPointer(0), (void *)data, ());
+
+ provider.Advance(1);
+
+ TEST_EQUAL(provider.IsDataExists(), true, ());
+ TEST_EQUAL(provider.GetVertexCount(), 9, ());
+ TEST_EQUAL(provider.GetRawPointer(0), (void *)(&data[5]), ());
+
+ provider.Advance(9);
+ TEST_EQUAL(provider.IsDataExists(), false, ());
+ TEST_EQUAL(provider.GetVertexCount(), 0, ());
+}
+
+UNIT_TEST(MixedStreamsTest)
+{
+ const int VERTEX_COUNT = 10;
+ AttributeProvider provider(2, 10);
+ float position[3 * VERTEX_COUNT];
+ float normal[2 * VERTEX_COUNT];
+
+ for (int i = 0; i < VERTEX_COUNT; ++i)
+ {
+ position[3 * i] = (float)i; // x
+ position[(3 * i) + 1] = 0.0; // y
+ position[(3 * i) + 2] = (float)i; // z
+ position[2 * i] = (float)i; // Nx
+ position[(2 * i) + 1] = 0.0; // Ny
+ }
+
+ {
+ BindingInfo binding(2);
+ {
+ BindingDecl & decl = binding.GetBindingDecl(0);
+ decl.m_attributeName = "position";
+ decl.m_componentCount = 2;
+ decl.m_componentType = GLConst::GLFloatType;
+ decl.m_offset = 0;
+ decl.m_stride = 3 * sizeof(float);
+ }
+
+ {
+ BindingDecl & decl = binding.GetBindingDecl(1);
+ decl.m_attributeName = "depth";
+ decl.m_componentCount = 1;
+ decl.m_componentType = GLConst::GLFloatType;
+ decl.m_offset = 2 * sizeof(float);
+ decl.m_stride = 3 * sizeof(float);
+ }
+
+ provider.InitStream(0, binding, ReferencePoiner<void>(position));
+ }
+
+ {
+ BindingInfo binding(1);
+ BindingDecl & decl = binding.GetBindingDecl(0);
+ decl.m_attributeName = "normal";
+ decl.m_componentCount = 2;
+ decl.m_componentType = GLConst::GLFloatType;
+ decl.m_offset = 0;
+ decl.m_stride = 0;
+ provider.InitStream(1, binding, ReferencePoiner<void>(normal));
+ }
+
+ TEST_EQUAL(provider.IsDataExists(), true, ());
+ TEST_EQUAL(provider.GetVertexCount(), 10, ());
+ TEST_EQUAL(provider.GetRawPointer(0), (void *)position, ());
+ TEST_EQUAL(provider.GetRawPointer(1), (void *)normal, ());
+
+ provider.Advance(1);
+
+ TEST_EQUAL(provider.IsDataExists(), true, ());
+ TEST_EQUAL(provider.GetVertexCount(), 9, ());
+ TEST_EQUAL(provider.GetRawPointer(0), (void *)(&position[3]), ());
+ TEST_EQUAL(provider.GetRawPointer(1), (void *)(&normal[2]), ());
+
+ provider.Advance(9);
+ TEST_EQUAL(provider.IsDataExists(), false, ());
+ TEST_EQUAL(provider.GetVertexCount(), 0, ());
+}
diff --git a/drape/drape_tests/drape_tests.pro b/drape/drape_tests/drape_tests.pro
index 3925e63d73..e90ec4e2a0 100644
--- a/drape/drape_tests/drape_tests.pro
+++ b/drape/drape_tests/drape_tests.pro
@@ -25,7 +25,8 @@ SOURCES += \
failure_reporter.cpp \
glmock_functions.cpp \
buffer_tests.cpp \
- uniform_value_tests.cpp
+ uniform_value_tests.cpp \
+ attribute_provides_tests.cpp
HEADERS += \
glmock_functions.hpp