Exemple #1
0
void AppearanceNode::outputContext(ostream &printStream, const char *indentString) 
{
	MaterialNode *material = getMaterialNodes();
	if (material != NULL) {
		if (material->isInstanceNode() == false) {
			if (material->getName() != NULL && strlen(material->getName()))
				printStream << indentString << "\t" << "material " << "DEF " << material->getName() << " Material {" << endl;
			else
				printStream << indentString << "\t" << "material Material {" << endl;
			material->Node::outputContext(printStream, indentString, "\t");
			printStream << indentString << "\t" << "}" << endl;
		}
		else 
			printStream << indentString << "\t" << "material USE " << material->getName() << endl;
	}

	TextureNode *texture = getTextureNode();
	if (texture != NULL) {
		if (texture->isInstanceNode() == false) {
			if (texture->getName() != NULL && strlen(texture->getName()))
				printStream << indentString << "\t" << "texture " << "DEF " << texture->getName() << " " << texture->Node::getType() << " {" << endl;
			else
				printStream << indentString << "\t" << "texture " << texture->Node::getType() << " {" << endl;
			texture->Node::outputContext(printStream, indentString, "\t");
			printStream << indentString << "\t" << "}" << endl;
		}
		else 
			printStream << indentString << "\t" << "texture USE " << texture->getName() << endl;
	}

	TextureTransformNode *textureTransform = getTextureTransformNodes();
	if (textureTransform != NULL) {
		if (textureTransform->isInstanceNode() == false) {
			if (textureTransform->getName() != NULL && strlen(textureTransform->getName()))
				printStream << indentString << "\t" << "textureTransform " << "DEF " << textureTransform->getName() << " TextureTransform {" << endl;
			else
				printStream << indentString << "\t" << "textureTransform TextureTransform {" << endl;
			textureTransform->Node::outputContext(printStream, indentString, "\t");
			printStream << indentString << "\t" << "}" << endl;
		}
		else 
			printStream << indentString << "\t" << "textureTransform USE " << textureTransform->getName() << endl;
	}
}
TEST(RepoBSONFactoryTest, MakeTextureNodeTest)
{
	std::string ext = "jpg";
	std::string name = "textureNode." + ext;
	std::string data = "The value of this texture is represented by this string as all it takes is a char*";
	int width = 100, height = 110;

	TextureNode tex = RepoBSONFactory::makeTextureNode(name, data.c_str(), data.size(), width, height);

	ASSERT_FALSE(tex.isEmpty());

	EXPECT_EQ(name, tex.getName());
	EXPECT_EQ(width, tex.getField(REPO_LABEL_WIDTH).Int());
	EXPECT_EQ(height, tex.getField(REPO_LABEL_HEIGHT).Int());
	EXPECT_EQ(ext, tex.getFileExtension());
	std::vector<char> rawOut = tex.getRawData();
	ASSERT_EQ(data.size(), rawOut.size());
	EXPECT_EQ(0, memcmp(data.c_str(), rawOut.data(), data.size()));

	//make sure the code doesn't fail over if for some reason the name does not contain the extension
	TextureNode tex2 = RepoBSONFactory::makeTextureNode("noExtensionName", data.c_str(), data.size(), width, height);
}