Skip to content

Commit 1d4612f

Browse files
committed
Fix issues
1 parent 9ea42ad commit 1d4612f

2 files changed

Lines changed: 34 additions & 14 deletions

File tree

modules/yup_audio_graph/graph/yup_AudioGraphModel.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,6 @@ Result modelReadCreationDataElement (const XmlElement& parent, MemoryBlock& bloc
154154
return Result::ok();
155155
}
156156

157-
if (element->getStringAttribute ("encoding") == "base64")
158-
return modelReadBase64Element (parent, "creationData", block);
159-
160157
auto* creationXml = element->getFirstChildElement();
161158
if (creationXml == nullptr)
162159
{

tests/yup_audio_graph/yup_AudioGraphProcessor.cpp

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,12 @@ AudioGraphNodeProperties externalProcessorProperties (float positionX = 0.0f, fl
519519
properties.positionX = positionX;
520520
properties.positionY = positionY;
521521

522+
XmlElement creationData ("externalPlugin");
523+
creationData.setAttribute ("pluginName", "Fake Plugin");
524+
creationData.setAttribute ("pluginIdentifier", "fake.plugin");
525+
522526
MemoryOutputStream stream (properties.creationData, false);
523-
stream.writeString ("Fake Plugin");
524-
stream.writeString ("fake.plugin");
527+
creationData.writeTo (stream);
525528
stream.flush();
526529

527530
return properties;
@@ -538,8 +541,17 @@ AudioGraphModel::NodeFactory statefulGainAndExternalFactory (int& externalLoadCo
538541
return makeResultValueFail ("Unknown node type");
539542

540543
MemoryInputStream stream (properties.creationData, false);
541-
const auto pluginName = stream.readString();
542-
externalIdentifier = stream.readString();
544+
const auto creationData = parseXML (stream.readEntireStreamAsString());
545+
546+
if (creationData == nullptr || ! creationData->hasTagName ("externalPlugin"))
547+
return makeResultValueFail ("Invalid external plugin creation data");
548+
549+
const auto pluginName = creationData->getStringAttribute ("pluginName");
550+
externalIdentifier = creationData->getStringAttribute ("pluginIdentifier");
551+
552+
if (pluginName.isEmpty() || externalIdentifier.isEmpty())
553+
return makeResultValueFail ("Invalid external plugin creation data");
554+
543555
++externalLoadCount;
544556

545557
return makeResultValueOk (std::make_unique<StatefulExternalProcessor> (pluginName));
@@ -1391,7 +1403,7 @@ TEST (AudioGraphProcessorTests, LoadStateFailsWhenFactoryIsMissing)
13911403
EXPECT_TRUE (destination.loadStateFromMemory (savedState).failed());
13921404
}
13931405

1394-
TEST (AudioGraphProcessorTests, LoadStateRecreatesExternalNodesWithOpaqueCreationData)
1406+
TEST (AudioGraphProcessorTests, LoadStateRecreatesExternalNodesWithXmlCreationData)
13951407
{
13961408
auto sourceModel = std::make_shared<AudioGraphModel>();
13971409
AudioGraphProcessor source (sourceModel);
@@ -1411,8 +1423,12 @@ TEST (AudioGraphProcessorTests, LoadStateRecreatesExternalNodesWithOpaqueCreatio
14111423
ASSERT_NE (nullptr, savedNodeElement);
14121424
auto* creationDataElement = savedNodeElement->getChildByName ("creationData");
14131425
ASSERT_NE (nullptr, creationDataElement);
1414-
EXPECT_EQ (String ("base64"), creationDataElement->getStringAttribute ("encoding"));
1415-
EXPECT_FALSE (creationDataElement->getAllSubText().trim().isEmpty());
1426+
EXPECT_TRUE (creationDataElement->getStringAttribute ("encoding").isEmpty());
1427+
1428+
auto* externalPluginElement = creationDataElement->getChildByName ("externalPlugin");
1429+
ASSERT_NE (nullptr, externalPluginElement);
1430+
EXPECT_EQ (String ("Fake Plugin"), externalPluginElement->getStringAttribute ("pluginName"));
1431+
EXPECT_EQ (String ("fake.plugin"), externalPluginElement->getStringAttribute ("pluginIdentifier"));
14161432

14171433
int externalLoadCount = 0;
14181434
String externalIdentifier;
@@ -1509,15 +1525,22 @@ TEST (AudioGraphProcessorTests, SaveStateWritesCompleteXmlTopology)
15091525
EXPECT_DOUBLE_EQ (11.0, gainElement->getDoubleAttribute ("positionX"));
15101526
EXPECT_DOUBLE_EQ (22.0, gainElement->getDoubleAttribute ("positionY"));
15111527
ASSERT_NE (nullptr, gainElement->getChildByName ("state"));
1512-
ASSERT_NE (nullptr, gainElement->getChildByName ("creationData"));
1528+
EXPECT_EQ (nullptr, gainElement->getChildByName ("creationData"));
15131529

15141530
auto* externalElement = nodesElement->getChildByAttribute ("id", String (static_cast<int64> (externalNode.getRawID())));
15151531
ASSERT_NE (nullptr, externalElement);
15161532
EXPECT_EQ (String ("externalPlugin"), externalElement->getStringAttribute ("identifier"));
15171533
EXPECT_EQ (String ("External Plugin"), externalElement->getStringAttribute ("name"));
15181534
EXPECT_DOUBLE_EQ (33.0, externalElement->getDoubleAttribute ("positionX"));
15191535
EXPECT_DOUBLE_EQ (44.0, externalElement->getDoubleAttribute ("positionY"));
1520-
EXPECT_FALSE (externalElement->getChildByName ("creationData")->getAllSubText().trim().isEmpty());
1536+
1537+
auto* creationDataElement = externalElement->getChildByName ("creationData");
1538+
ASSERT_NE (nullptr, creationDataElement);
1539+
1540+
auto* externalPluginElement = creationDataElement->getChildByName ("externalPlugin");
1541+
ASSERT_NE (nullptr, externalPluginElement);
1542+
EXPECT_EQ (String ("Fake Plugin"), externalPluginElement->getStringAttribute ("pluginName"));
1543+
EXPECT_EQ (String ("fake.plugin"), externalPluginElement->getStringAttribute ("pluginIdentifier"));
15211544

15221545
auto* connectionsElement = xml->getChildByName ("connections");
15231546
ASSERT_NE (nullptr, connectionsElement);
@@ -1636,7 +1659,7 @@ TEST (AudioGraphProcessorTests, LoadStateRejectsMissingRequiredXmlSections)
16361659
EXPECT_TRUE (graph.loadStateFromMemory (memoryBlockFromString (missingConnectionsXml)).failed());
16371660
}
16381661

1639-
TEST (AudioGraphProcessorTests, LoadStateRejectsInvalidBase64Payloads)
1662+
TEST (AudioGraphProcessorTests, LoadStateRejectsInvalidNodeStateAndCreationDataPayloads)
16401663
{
16411664
auto sourceModel = std::make_shared<AudioGraphModel>();
16421665
AudioGraphProcessor source (sourceModel);
@@ -1671,7 +1694,7 @@ TEST (AudioGraphProcessorTests, LoadStateRejectsInvalidBase64Payloads)
16711694
auto* creationDataElement = invalidCreationData->getChildByName ("nodes")->getChildByName ("node")->getChildByName ("creationData");
16721695
ASSERT_NE (nullptr, creationDataElement);
16731696
creationDataElement->deleteAllChildElements();
1674-
creationDataElement->addTextElement ("not-base64");
1697+
creationDataElement->addChildElement (new XmlElement ("externalPlugin"));
16751698

16761699
EXPECT_TRUE (destination.loadStateFromMemory (memoryBlockFromXml (*invalidCreationData)).failed());
16771700
EXPECT_EQ (0, externalLoadCount);

0 commit comments

Comments
 (0)