Audacity 3.2.0
GetAcidizerTagsTests.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 GetAcidizerTagsTests.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
11#include "AcidizerTags.h"
12#include "GetAcidizerTags.h"
13#include "LibsndfileTagger.h"
14
15#include "FileFormats.h"
16#include "sndfile.h"
17#include <array>
18#include <catch2/catch.hpp>
19#include <filesystem>
20#include <fstream>
21#include <iostream>
22
23namespace LibImportExport
24{
25using namespace LibFileFormats;
26
27TEST_CASE("GetAcidizerTags")
28{
29 SECTION("returns null if")
30 {
31 SECTION("there is no loop info")
32 {
34 const auto actual = GetAcidizerTags(tagger.ReopenInReadMode(), {});
35 REQUIRE(!actual.has_value());
36 }
37 SECTION("tempo is set but the distributor isn't whitelisted")
38 {
40 tagger.AddAcidizerTags(AcidizerTags::Loop { 120. });
41 tagger.AddDistributorInfo("Distributor Zen");
42 const auto actual = GetAcidizerTags(
43 tagger.ReopenInReadMode(),
44 { "foo", "Distributor Z", "Distributor Zen 2" });
45 REQUIRE(!actual.has_value());
46 }
47 }
48
49 SECTION("returns valid info if")
50 {
51 SECTION("OneShot is set")
52 {
55 const auto actual = GetAcidizerTags(tagger.ReopenInReadMode(), {});
56 REQUIRE(actual.has_value());
57 REQUIRE(actual->isOneShot);
58 }
59 SECTION("Beats is set")
60 {
61 // 20 beats in 10 seconds -> 120 bpm.
62 Test::LibsndfileTagger tagger { 10. };
63 constexpr auto numBeats = 20;
64 tagger.AddAcidizerTags(Test::AcidizerTags::Beats { numBeats });
65 auto& file = tagger.ReopenInReadMode();
66 const auto actual = GetAcidizerTags(file, {});
67 REQUIRE(actual.has_value());
68 SF_INFO info;
69 sf_command(&file, SFC_GET_CURRENT_SF_INFO, &info, sizeof(SF_INFO));
70 const auto durationAfterClose = 1. * info.frames / info.samplerate;
71 const auto expectedBpm = numBeats * 60 / durationAfterClose;
72 REQUIRE(actual->bpm == Approx(expectedBpm));
73 REQUIRE(actual->isOneShot == false);
74 };
75 SECTION("Tempo is set and the distributor is whitelisted")
76 {
78 tagger.AddAcidizerTags(AcidizerTags::Loop { 120. });
79 tagger.AddDistributorInfo("Trusted Distributor");
80 const auto actual = GetAcidizerTags(
81 tagger.ReopenInReadMode(), { "Trusted Distributor" });
82 REQUIRE(actual.has_value());
83 REQUIRE(actual->bpm == 120.);
84 REQUIRE(actual->isOneShot == false);
85 }
86 }
87}
88} // namespace LibImportExport
When adding tags, the allocated memory must be preserved until the file is closed....
void AddAcidizerTags(const Test::AcidizerTags &acidTags)
void AddDistributorInfo(const std::string &distributor)
TEST_CASE("GetAcidizerTags")
std::optional< LibFileFormats::AcidizerTags > GetAcidizerTags(SNDFILE &file, const std::vector< std::string > &trustedDistributors)
Get the Acidizer tags from a file if from a trusted distributor.