aboutsummaryrefslogtreecommitdiff
path: root/cast/streaming/sender_session_unittest.cc
diff options
context:
space:
mode:
authorYuri Wiitala <miu@chromium.org>2020-10-26 12:30:13 -0700
committerCommit Bot <commit-bot@chromium.org>2020-10-26 20:44:44 +0000
commit2837c9f0c416803cbab994f1fe10296d2a132971 (patch)
treedae3d9a0167f1bc6a56ee65be4f329ce086b73ed /cast/streaming/sender_session_unittest.cc
parent83e50af3e0bd628e7307e67e0ae1c6a611b8d7bb (diff)
downloadopenscreen-2837c9f0c416803cbab994f1fe10296d2a132971.tar.gz
Add StringPrintf() wrapper utility.
Adds an efficient wrapper around std::snprintf() that returns the formatted result in a std::string. Background: The issue of either 1) wanting to use absl::StrFormat() without bloating our binary sizes, or 2) manually writing char[] buffer code around std::snprintf() has come up several times over the past year or so. So, this new utility is about reducing friction and improving future developer velocity. Change-Id: Ie898f91575852b06d59844dd564a0da03df1f7ed Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/2487768 Commit-Queue: Yuri Wiitala <miu@chromium.org> Reviewed-by: Yuri Wiitala <miu@chromium.org> Reviewed-by: Brandon Tolsch <btolsch@chromium.org>
Diffstat (limited to 'cast/streaming/sender_session_unittest.cc')
-rw-r--r--cast/streaming/sender_session_unittest.cc28
1 files changed, 13 insertions, 15 deletions
diff --git a/cast/streaming/sender_session_unittest.cc b/cast/streaming/sender_session_unittest.cc
index d56a9f30..f5e1117b 100644
--- a/cast/streaming/sender_session_unittest.cc
+++ b/cast/streaming/sender_session_unittest.cc
@@ -17,6 +17,7 @@
#include "platform/test/fake_clock.h"
#include "platform/test/fake_task_runner.h"
#include "util/chrono_helpers.h"
+#include "util/stringprintf.h"
using ::testing::_;
using ::testing::InSequence;
@@ -180,21 +181,18 @@ class SenderSessionTest : public ::testing::Test {
const int video_index = video_stream["index"].asInt();
const int video_ssrc = video_stream["ssrc"].asUInt();
- constexpr size_t kAnswerSize = 512u;
- char answer[kAnswerSize];
- snprintf(answer, kAnswerSize, R"({ "type": "ANSWER",
- "seqNum": %d,
- "answer": {
- "castMode": "mirroring",
- "udpPort": 1234,
- "sendIndexes": [%d, %d],
- "ssrcs": [%d, %d]
- }
- })",
- offer["seqNum"].asInt(), audio_index, video_index, audio_ssrc + 1,
- video_ssrc + 1);
-
- return std::string(answer);
+ constexpr char kAnswerTemplate[] = R"({
+ "type": "ANSWER",
+ "seqNum": %d,
+ "answer": {
+ "castMode": "mirroring",
+ "udpPort": 1234,
+ "sendIndexes": [%d, %d],
+ "ssrcs": [%d, %d]
+ }
+ })";
+ return StringPrintf(kAnswerTemplate, offer["seqNum"].asInt(), audio_index,
+ video_index, audio_ssrc + 1, video_ssrc + 1);
}
protected: