2024-12-22 22:31:05 +01:00
/*
OutputProxyProvider ( Test ) - verify accessing an output sink via BufferProvider protocol
Copyright ( C )
2024 , Hermann Vosseler < Ichthyostega @ web . de >
* * Lumiera * * is free software ; you can redistribute it and / or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation ; either version 2 of the License , or ( at your
option ) any later version . See the file COPYING for further details .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2025-04-26 23:59:29 +02:00
/** @file output-proxy-provider-test.cpp
2024-12-22 22:31:05 +01:00
* * unit test \ ref OutputProxyProvider_test
*/
2026-03-06 21:34:20 +01:00
# include "test/run.hpp"
2024-12-22 22:31:05 +01:00
//#include "steam/play/diagnostic-output-slot.hpp"
2026-02-19 23:21:01 +01:00
# include "steam/engine/buffer-proxy-adaptor.hpp"
2024-12-22 22:31:05 +01:00
# include "steam/engine/test-rand-ontology.hpp"
2026-02-26 23:25:07 +01:00
# include "lib/meta/prop-builder.hpp"
2026-03-06 21:34:20 +01:00
# include "test/diagnostic-output.hpp" ////////////////////TODO
2024-12-22 22:31:05 +01:00
namespace steam {
namespace engine {
namespace test {
2026-02-26 23:25:07 +01:00
using lib : : meta : : PropBuilder ;
2024-12-22 22:31:05 +01:00
/***************************************************************/ /**
2024-12-23 23:55:00 +01:00
* @ test verify the design of OutputSlot and BufferProvider by
* implementing a delegating BufferProvider to expose
* output data buffers provided from _some implementation . _
2026-02-19 23:21:01 +01:00
* @ todo 2 / 2026 now using this setup for prototyping /////////////////////////////////////////////////TICKET #1415 : explore this design idea through prototyping
2024-12-22 22:31:05 +01:00
*/
class OutputProxyProvider_test : public Test
{
virtual void
2025-06-07 23:59:57 +02:00
run ( Arg )
2024-12-22 22:31:05 +01:00
{
2026-02-26 23:25:07 +01:00
BufferState state { NIL } ;
2026-02-22 23:39:10 +01:00
2024-12-22 22:31:05 +01:00
// setup with notification callback
2026-02-26 23:25:07 +01:00
BufferProxyAdaptor proxPro { PropBuilder ( )
. define ( PROP_FIELD ( on_lock ) , [ & ] { state = LOCKED ; } )
. define ( PROP_FIELD ( on_emit ) , [ & ] { state = EMITTED ; } )
. define ( PROP_FIELD ( on_release ) , [ & ] { state = FREE ; } )
} ;
2024-12-22 22:31:05 +01:00
// Assuming some data block is »given«
seedRand ( ) ;
size_t frameNr = defaultGen . u64 ( ) ;
TestFrame dataBlock ( frameNr ) ;
2026-02-26 23:25:07 +01:00
CHECK ( dataBlock . isPristine ( ) ) ;
CHECK ( state = = NIL ) ;
2024-12-22 22:31:05 +01:00
2026-02-22 23:39:10 +01:00
BuffHandle handle = proxPro . lockBuffer ( dataBlock ) ;
2026-02-26 23:25:07 +01:00
CHECK ( state = = LOCKED ) ;
2024-12-22 22:31:05 +01:00
// Now a »client« can do awful things to the buffer...
CHECK ( handle . isValid ( ) ) ;
auto & data = handle . accessAs < TestFrame > ( ) ;
uint64_t param = defaultGen . u64 ( ) ;
2025-01-06 22:00:29 +01:00
ont : : manipulateFrame ( & data , & data , param ) ;
2026-02-26 23:25:07 +01:00
HashVal check = data . getChecksum ( ) ;
2024-12-22 22:31:05 +01:00
// »client« is done...
handle . emit ( ) ;
2026-02-26 23:25:07 +01:00
CHECK ( state = = EMITTED ) ;
2024-12-22 22:31:05 +01:00
// end usage cycle
handle . release ( ) ;
2026-02-26 23:25:07 +01:00
CHECK ( state = = FREE ) ;
2024-12-22 22:31:05 +01:00
CHECK ( not handle . isValid ( ) ) ;
CHECK ( not dataBlock . isPristine ( ) ) ;
CHECK ( dataBlock . isValid ( ) ) ;
2026-02-26 23:25:07 +01:00
CHECK ( check = = dataBlock . getChecksum ( ) ) ;
2024-12-22 22:31:05 +01:00
}
} ;
/** Register this test class... */
LAUNCHER ( OutputProxyProvider_test , " unit play " ) ;
} } } // namespace steam::play::test